VBScript Count Files

This script will count the numbers of files in a folder and output to file.

Dim fso, folder, files, OutputFile
Dim strPath, filecnt

‘ Create a FileSystemObject
Set fso = CreateObject(“Scripting.FileSystemObject”)

‘ Create text file to output test data
Set OutputFile = fso.CreateTextFile(“c:\Script\ScriptOutput.txt”, True)

‘ Define folder we want to list files from
strPath = “c:\Script\”

set objFSO = createobject(“Scripting.FileSystemObject”)

GetFolders strPath

sub GetFolders(byval strDirectory)
set objFolder = objFSO.GetFolder(strDirectory)
for each objFolder in objFolder.SubFolders
Set folder = fso.GetFolder(objFolder.Path)
Set files = folder.Files
‘ Loop through each file
filecnt = 0
For each item In files
filecnt = filecnt + 1
‘ Output file properties to a text file

OutputFile.WriteLine(“This Folder –> ‘” & folder & “‘ has ” & filecnt & ” Files”)
GetFolders objFolder.Path

end sub
wscript.echo “Script has finished running”
‘ Close text file

email me