Solved

Modify Output to show folder size output in MBs

Posted on 2011-03-11
1
375 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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