File Count and Folder Size Analysis Process

How does the file count and folder size process work?

  1. Run a Directory of the folders and files under analysis with a export pipe to a text file
  2. Run the CountFilesInFolders.vbs process which reads the text file created above and builds a CSV file for speadsheet use
  3. Open the newly created Folder-File-Count-Analysis.csv file with you spreadsheet program

What does the Folder File Count CSV results look like?

Directory Name Directory File Count Directory Size in Bytes
C:\ 20 42187801
C:\WINDOWS 325 45192448
C:\WINDOWS\system 29 1112411

What can the Folder File Count results be used for?

Files Directory Process in Detail

The directory list creates a text file similar to shortened example below. The CountFilesInFolders.vbs reads the text file from top to bottom.
  1. It looks for the Directory line and notes the the Directory Name
  2. Ignores <DIR> lines
  3. Counts file lines 
  4. Looks for the Files(s) lines and creates a results like: Directory Name, File Count of Directory and Folder Size in Bytes.
 Volume in drive C is HDD
  Directory of C:\
04/22/2010 09:18 AM    <DIR>         Desktop
01/02/2008 04:42 PM   <DIR>         Manuals
11/08/2005 09:40AM          133,442 additions.log
04/25/2010 10:43PM                0 cresults.txt
             20 File(s)     42,187,801 bytes
 Directory of C:\Program Files
 12/19/2008 10:31 AM   <DIR>         Windows Media Player
               0 File(s)             0 bytes

 Directory of C:\Program Files\Windows Media Player
 09/22/2004 06:45 PM           12,631 eula.txt
 04/14/2008 10:12AM            4,639 mplayer2.exe
              18 File(s)      4,215,605bytes

Count Files in Folders VBscript code listing

'Program to allow analysis of folder names, folder sizes and folder filecounts
'    Program code provided by  The code is provided free in a "as is" format. The concept may translate into other languages.
'    Requirements: Windows computer with Internet Explorer 6 or later. Some computer knowledge of Command Prompt.
'Step 1 From a Command Prompt Start - Run cmd ,Run a Directory of the folder or drive in question
'E.g.   dir *.* /s > results.txt
'       dir c:\progra~1\*.* /s >presults.txt
'       dir c:\*.* /s > cresults.txt
'       Wait until the results file is built. Drive activity should be stopped and the result file not growing any more.
'       This process may take up to 10 minutes to complete.
'Step 2 Run the CountFileInFolders.vbs program. The reads the above text file and creates a CSV file.
'      One question is asked. Where is the directory file. E.g. presults.txt or c:\cresults.txt
'      When the program is finished a message box appears. Click OK.
'Step 3 Open the Folder-File-Count-Log.csv created using your spreadsheet program.     
'      See the folders with the most files or largest in size.    
'      Check if file creation processes are operating as expected.
'        Check if file copy processes are operating as expected.   
'      See where hard drive space is being used and delete the unwanted to extend the useful life of your computer.
Dim fso, WshShell, Resultfile, workingfile, Forout, Answer,DirectoryFile,DirectoryLine
Dim FolderName, FileCount, TheLength, DirectoryName, DirectoryCount,DirectoryByteSize
Dim Check1, Check2, Check3, Check4
Dim MyArray
Dim ArrayCount
Set fso = CreateObject("Scripting.FileSystemObject")
Set Resultfile = fso.opentextfile("Folder-File-Count-Analysis.csv",2,True) 'For writing ResultsLog
ResultFile.WriteLine "Directory Name, Directory File Count, Directory Size in Bytes"
Answer= inputbox("Enter the file path name extension of the directory listing","Folder File Count Process")
Set DirectoryFile = fso.opentextfile(Answer,1) 'For reading
DirectoryName = ""
DirectoryCount = 0
Do Until DirectoryFile.AtEndOfStream = True
DirectoryLine = DirectoryFile.ReadLine
TheLength= len(DirectoryLine)
MyArray= Split(DirectoryLine," ",-1,1)
ArrayCount= Ubound(MyArray)
Check1= Instr(1,DirectoryLine,"Directory",1)
Check2= Instr(1,DirectoryLine,"<DIR>",1)
Check3= Instr(1,DirectoryLine,"File(s)",1)
IfCheck1 > 0 Then
DirectoryName= right(DirectoryLine, thelength-14)
End If
If ArrayCount > 2 Then
If isdate(Myarray(0)) And Check2 = 0 Then
DirectoryCount= DirectoryCount + 1
End If
End If
If Check3 > 0 And DirectoryCount > 0 Then
Check4 = cstr(Myarray(arraycount-1))
DirectoryByteSize= replace(Check4,",","",1,-1,1)
Forout= DirectoryName + "," + cstr(DirectoryCount) + "," + DirectoryByteSize
ResultFile.WriteLine Forout
DirectoryName = ""
DirectoryCount = 0
End If
msgbox "Finished the reading of the Directory File.Folder-File-Count-Analysis.csv created in the local directory for analysis by spreadsheet program."

Program For Download

Create a new directory such as C:\Tools\CountFilesInFolders. Save the program file below into the new directory. Result file is saved in the same directory as the program file.

CountFileInFolders.vbs   The is the Count Files In Folders VBscript program
CountFileInFolders.txt      If the above is prevented from downloading, then download the text file version and rename the extension to vbs.

Facebook Linked In Delicious Reddit Tweet