Glad to see you got the script working. Not sure what could have caused the error on you other machine. VBScript is very forgiving where objects and variables are destroyed when the script ends. An exception is application objects (Word, Excel, etc) where they must be Quit, otherwise you'll find them in your task list long after the script ends.
Last time I have the problem on the script to do the check the size, but I get message from my boss, he needs to check the case is run the script can show all the size of directory at once.
Not sure what you're asking. I tweaked the script to display the subfolders. I also added a unit of measure to the CSV file so the numbers make more sense.
Be aware that the FileSystemObject recurses the directory tree when computing the size property. Each folder size includes all of it's subfolders. The numbers you see are correct but may appear inflated.
It's possible to retrieve the files from a recursive folder search, but the total size of the files will probably not add up to the size of the folder unless the folder has no subfolders. This would be easier in batch, however batch arithmetic only deals with integers. This can lead to some wildly inaccurate results. Hey! 700k bytes here, 700k bytes there, and pretty soon you're talking about some serious real estate.
Const ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set fs = fso.OpenTextFile("c:\temp\DirSize.csv", ForAppending, True)
Do
WScript.StdOut.Write "Please enter directory name: "
strFolder = WScript.StdIn.ReadLine
If fso.FolderExists(strFolder) Then
Exit Do
Else
WScript.StdOut.Write "Invalid Directory ... Try Again" & vbCrLf
End If
Loop
Set f = fso.GetFolder(strFolder)
WScript.Echo f.Path & ": " & GetEditSize(f.Size)
fs.WriteLine f.Path & "," & Replace(GetEditSize(f.Size), " ", ",")
GetThePaths(f)
fs.Close
Sub GetThePaths(Folder)
For Each Subfolder in Folder.SubFolders
WScript.Echo SubFolder.Path & ": " & GetEditSize(SubFolder.Size)
fs.WriteLine SubFolder.Path & "," & Replace(GetEditSize(SubFolder.Size), " ", ",")
GetThePaths Subfolder
Next
End Sub
Function GetEditSize(intSize)
If intSize => (1024*1024*1024*1024) Then
GetEditSize = Round(FormatNumber((intSize/(1024*1024*1024)), 4,, TriStateTrue), 2) & " TB"
ElseIf intSize => (1024*1024*1024) Then
GetEditSize = Round(FormatNumber((intSize/(1024*1024*1024)), 4,, TriStateTrue), 2) & " GB"
ElseIf intSize => (1024*1024) Then
GetEditSize = Round(FormatNumber((intSize/(1024*1024)), 4,, TriStateTrue), 2) & " MB"
ElseIf intsize => 1024 Then
GetEditSize = Round(FormatNumber((intSize/1024), 4,, TriStateTrue), 2) & " KB"
Else
GetEditSize = intSize & " Bytes"
End If
End Function
I'm sure we'' here from you again.