Link to home
Start Free TrialLog in
Avatar of CCG3
CCG3Flag for United States of America

asked on

Modify Output to show folder size output in MBs

need help changing this VBS script to output MBs instead of bytes (fsize at the bottom)


On Error Resume Next

inputfile="C:\folderlist.xls" 'path of excel file
outputfile="C:\output.txt" 'path of output file to be written

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(inputfile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outputfile=objfso.OpenTextFile(outputfile,2)

intRow = 1

Do Until objExcel.Cells(intRow,1).Value = ""
    strcomputer=Trim(objExcel.Cells(intRow, 1).Value)
    folder=Trim(objExcel.Cells(intRow, 2).Value)
    folder_path="\\"&strcomputer&"\"& folder
    WScript.Echo folder_path
    Set objShell = CreateObject("Wscript.Shell")
    command = "du.exe " & folder_path
   
    Set objExec = objShell.Exec(Command)
    Do While Not objExec.StdOut.AtEndOfStream
        strText = Trim(objExec.StdOut.ReadLine())
        ' Test or display strText
        WScript.Echo strText  
        If InStr(strText,"Size:         ")>0 Then
            fsize=Replace(strText,"Size:         ","")
            fsize=Replace(fsize," bytes","")
            fsizedbl=CDbl(fsize)
            WScript.Echo "File size " & fsizedbl
            outputfile.WriteLine strcomputer & "," & folder & "," &  fsize
            Exit Do
        End If
    Loop
   
    intRow = intRow + 1
Loop

outputfile.Close
objExcel.Quit
ASKER CERTIFIED SOLUTION
Avatar of McOz
McOz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial