...Because someone's gotta tell the story...


To return to the main Blog List, click Full Blog Listing.


System Center

VBScript: Count of all files in all subfolders

Thursday, June 9, 2011 in System Center (Views: 6020)
Here is a script that may be helpful that I threw together for looking at potential SMS or SCCM backlogs. This will count any files under the specified directory and any subdirectory, without listing the actual files, just counts. Would be helpful if you're just looking for where the big pockets of files are hiding.

If you're wondering, the inboxmon.log can be helpful in this case, but used this script to find out what other files could be hiding in the inboxes..

Hope you find this useful.

Option Explicit

Dim fs
Set fs = CreateObject("scripting.filesystemobject")

' Count files in the directory by Arguments
' Syntax: listcount.vbs (FolderName)
if wscript.arguments.count < 1 then
wscript.echo "Incorrect command line."
wscript.echo "Syntax: cscript listcount.vbs (foldername)"
wscript.echo CountFiles (wscript.arguments(0))
end if

Function CountFiles (ByVal StrFolder)
Dim ParentFld
Dim SubFld
Dim IntCount

Set ParentFld = fs.GetFolder (StrFolder)

' count the number of files in the current directory
IntCount = ParentFld.Files.Count

For Each SubFld In ParentFld.SubFolders
' count all files in each subfolder
IntCount = IntCount + CountFiles(SubFld.Path)
'If you just want the one directory, you can comment the following line.
wscript.echo wscript.arguments(0) & "\" & ParentFld.Name & "\" & SubFld.Name & ": " & intcount

'Returns the counted files, remove the comment if you just want the one directory
'CountFiles = IntCount
End Function


Related Blogs You May Be Interested In:

To leave a comment, please log in and/or register.