Re: vbscript to find largest directory ?

Tech-Archive recommends: Fix windows errors by optimizing your registry



"bitshift" <jobob@xxxxxxx> wrote in message
news:e9YZ1dlQIHA.3388@xxxxxxxxxxxxxxxxxxxxxxx
I need to find the largest directory on my system.
What is a good method to use to do this with vbscript ?
just loop through every top level directory
on the root of the drive and look at the directory size ?

That will work. Will this help? Watch for Word-wrap.

Option Explicit
'****
'* "Largest.vbs" identifies the largest folder on drive "cDRV".
'****
'*
'* Declare Constants
'*
Const cVBS = "Largest.vbs"
Const cDRV = "C:\"
'*
'* Declare Variables
'*
Dim strFOL
Dim intSAV
Dim strSAV
Dim intSIZ
intSIZ = 0
Dim strSIZ
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'*
'* Call Subfolders()
'*
Call Subfolders(cDRV)
'*
'* Destroy Objects
'*
Set objFSO = Nothing
'*
'* Completion Message
'*
MsgBox strSAV & vbCrLf & FormatNumber(intSAV,0) & "
bytes",vbInformation,cVBS

Sub Subfolders(folder)
'****
'* Identify subfolders under a given drive or folder.
'****
'*
'* Get Subfolders
'*
For Each strFOL In objFSO.GetFolder(folder).SubFolders
intSIZ = objFSO.GetFolder(strFOL.Path).Size
strSIZ = FormatNumber(intSIZ,0)
If intSAV < intSIZ Then
intSAV = intSIZ
strSAV = strFOL.Path
End If
'****** WScript.Echo Space(16-Len(strSIZ)) & strSIZ & " bytes = " & strFOL
'****** Call Subfolders(strFOL.Path)
Next
End Sub


You could modify "cDRV" to point to a folder to identify
the largest (by number of bytes) subfolder under it.

Note that the "size" identifies the number of bytes and
not the actual space used. Run "chkdsk" from the command
prompt to identify the size of an "allocation unit". For example,
my C: drive reports "32,768 bytes in each allocation unit"; thus,
each file will actually use a multiple of that number: a 1-byte file
uses 32,768 bytes (32KB) and a 33KB file will use 64KB.

You might uncomment the two "'****** " lines and run this
via CSCRIPT piping the output to a "log" file to identify the
size of every subfolder. Subsequently, you could sort the log.

cscript.exe //nologo Largest.vbs > Largest.log
sort /R < Largest.log > Largest.txt




.



Relevant Pages