#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    82
    Rep Power
    3

    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
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0
    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
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    82
    Rep Power
    3
    Thank you medialint and Rukbat! You guys rock!
    testerV

IMN logo majestic logo threadwatch logo seochat tools logo