November 6th, 2012, 05:12 PM
-
Subfolders Path\Name\Size to text file
Hi,
I’m trying to write a code, it supposed to scan a folder for subfolders and print to a log file their Path\Folder name\Folder size.
I decided to get the subfolders names and the size and print it to a text file.
The code I got so far can echo Name&Size butit does not want to print it in to a text file.
Could you guys help me with this?
Thanks, testerV
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Sub_Dirsize.txt", True)
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder("C:\TestFiles")
for Each folder in objFolder.SubFolders
On Error Resume Next
size = folder.size
if Err.Number <> 0 Then
size = -1
objFile.WriteLine "folder.name,size "
end if
' wscript.echo folder.name,size
Next
WScript.Quit
November 6th, 2012, 05:48 PM
-
Remove the quotes from the writeline (1) and take it out of the if conditional (2).
(1) You'd literally be writing what's in the quotes to the file thus it would literally look like
folder.name,size
folder.name,size
folder.name,size
folder.name,size
folder.name,size
(2) You'd only be writing a line if there was an error.
medialint.com
“Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
November 6th, 2012, 08:02 PM
-
Try it this way:
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Sub_Dirsize.txt", True)
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder("C:\TestFiles")
for Each folder in objFolder.SubFolders
On Error Resume Next
size = folder.size
if Err.Number <> 0 Then size = -1
On Error GoTo 0
objFile.WriteLine folder.name,size
Next
WScript.Quit
November 6th, 2012, 11:14 PM
-
Thank you medialint and Rukbat! You guys rock!
testerV