What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Count number of subfolders?

Votes:

0

I'd like to count the number of sub-folders underneath a folder. Is this possible?

count folder sensor

Created on Oct 27, 2011 7:45:35 PM



Best Answer

Accepted Answer

Votes:

0

This can be done with a simple batch file sensor.

Create a new file in the \Custom Sensors\EXE folder of your PRTG installation called FolderCount.bat and paste the following code:

@echo off
if .%1==. goto noparameter
if not .%2==. goto tomanyparameters
if not exist %1\nul goto notexist

FOR /F %%A in ('dir %1 /A:D') do set count=%%A
set /a count=count
set /a count=count-2
echo %count%:Folders
exit 0

:noparameter
echo Please supply a foldername.
exit 2

:tomanyparameters
echo Your foldername contains spaces, please enclose your foldername in double quotes.
exit 2

:notexist
echo Folder %1% not found.
exit 2

Now create a new custom sensor, select FolderCount.bat and provide the root folder in the parameters section of the sensor.

Created on Oct 28, 2011 2:44:31 PM

Last change on Oct 28, 2011 6:53:09 PM by  Torsten Lindner [Paessler Support]



7 Replies

Votes:

0

it is not yet possible, but we might include it soon.

Created on Oct 28, 2011 8:29:30 AM by  Aurelio Lombardi [Paessler Support]



Accepted Answer

Votes:

0

This can be done with a simple batch file sensor.

Create a new file in the \Custom Sensors\EXE folder of your PRTG installation called FolderCount.bat and paste the following code:

@echo off
if .%1==. goto noparameter
if not .%2==. goto tomanyparameters
if not exist %1\nul goto notexist

FOR /F %%A in ('dir %1 /A:D') do set count=%%A
set /a count=count
set /a count=count-2
echo %count%:Folders
exit 0

:noparameter
echo Please supply a foldername.
exit 2

:tomanyparameters
echo Your foldername contains spaces, please enclose your foldername in double quotes.
exit 2

:notexist
echo Folder %1% not found.
exit 2

Now create a new custom sensor, select FolderCount.bat and provide the root folder in the parameters section of the sensor.

Created on Oct 28, 2011 2:44:31 PM

Last change on Oct 28, 2011 6:53:09 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Gered, Thanks for the help!

Right now the parameter is
servername\d$\folder1 The return value keeps coming back as -2#

Created on Oct 28, 2011 4:15:01 PM



Votes:

0

Disregard. This script worked great! Thanks!

Created on Oct 28, 2011 4:20:06 PM



Votes:

0

That means that the server\folder name cannot be found. This can be a rights issue, your PRTG server running under the system account might not have access to this share. Also keep in mind that if your server\folder name contains spaces, you will have to enclose it in double quotes, so servername\d$\folder 1 becomes "servername\d$\folder 1"

I have added some extra checks to the code in my original post.

Regards,

Created on Oct 28, 2011 5:16:07 PM



Votes:

0

Still having a little trouble... Should be formatting the parameter like so?
servername\d$\folder123

I can UNC to the folder just fine from the Probe and Server.

Created on Oct 28, 2011 7:38:43 PM



Votes:

0

Anything that words with the dir command will do, but keep in mind that your PRTG server runs as a service with credentials that might not have access to the folder.

In your case, using an administrative share (d$) that is only visible for administrators, your PRTG server running on the local system account will not have acess to this share.

How can this be solved?

1. You can try to not run the sensor in the security context of the probe, but the security context of the parent device (see the sensors settings page). You will need to supply windows credentials to the parent device for this.

2. Install a remote probe on your "servername". This remote probe will also run on the local system account, but will have access to the D drive. In this case you will have to use "d:\folder123" as parameter ant NOT use the d$ share.

3. Another way is to make a (real) share for the "folder123" and create a PRTG user in your network that has access to this share. The next thing to do will be running your PRTG server with the credentials of this PRTG user.

4. Quick and dirty: Run your PRTG server service with admin credentials. Note: this will bring up security issues and is not recommended for production environments.

Regards,

Created on Oct 31, 2011 11:38:36 AM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.