Solved

Modify Output to show folder size output in MBs

Posted on 2011-03-11
1
374 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:CCG3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
McOz earned 500 total points
ID: 35110859
change this:
fsizedbl=CDbl(fsize)

Open in new window

to this:
fsizedbl=CDbl(fsize)/1048576

Open in new window


bytes = kilobytes/1024
kilobytes = megabytes/1024

Cheers
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question