Sunday, December 4, 2005


How to get the dimensions of files using the FileSystemObject

I got a question earlier this evening on how to get the dimensions of a file using the FileSystemObject. I put together the VBScript below that goes through all files of C:\ and lists the dimensions using the .Size property.

Option Explicit
'Purpose: List sub directories with files and their sizes
dim oFS
dim oDir
set oFS = CreateObject("Scripting.FileSystemObject")
set oDir = oFS.GetFolder("C:\")
listDir (oDir)
sub listDir(rootDir)
'Purpose: List contents of this directory and all subdirectories
dim oDir
dim oFile
    'Call ourselves for all sub directories
    WScript.echo rootDir.Path
    for each oDir in rootDir.SubFolders
        listDir (oDir)
    'List all the files in this directory
    for each oFile in rootDir.Files
        WScript.echo vbTab & & " [" & oFile.Size & " bytes]"
end sub

No comments:

Post a Comment