Sunday, April 1, 2007

Directory Scan

' Given a root directory, this script will scan for
' subdirectories and will output the size of each subdirectory.

On Error Resume Next

Dim RootDir, FileSystem, RootFolder, SubFolders, Folder
Dim FolderSize, Tmp

If Wscript.Arguments.Count <> 1 Then
Wscript.Echo "USAGE: dirscan.vbs [root directory]"
Wscript.Echo ""
Wscript.Echo " Given a root directory, dirscan will scan"
Wscript.Echo " all subdirectories and output the size of"
Wscript.Echo " each subdirectory."
Wscript.Quit 0
Else
RootDir = Wscript.Arguments(0)
Wscript.Echo "Root directory is: " & RootDir
Wscript.Echo ""
End If

Set FileSystem = CreateObject("Scripting.FileSystemObject")
Set RootFolder = FileSystem.GetFolder(RootDir)
If Err.Number <> 0 Then
' Display the error that occurred
Wscript.Echo "(" & Err.Number & ") " & Err.Description
Wscript.Echo ""
Wscript.Echo "The path that you entered is invalid, please " & _
"select a different path."
Wscript.Quit Err.Number
End If

Set SubFolders = RootFolder.SubFolders

For Each Folder In SubFolders
FolderSize = Folder.Size
Tmp = FormatNumber(FolderSize, 0, 0, 0, -1)
Tmp = Right(Space(20) & Tmp, 20)
Wscript.Echo Tmp & " " & Folder.Path
Next

1 comment:

Anonymous said...

Excellent way of telling, and nice article to take facts concerning my presentation topic, which i am
going to present in university.

Also visit my blog; cardsharing servers

Related Titles

 
visitors since March 26 2007
©2007