|
Answer» Hi all... starting this new thread as directed.
here is what i need help with:
i need to write a batch file (preferably .bat not .vbs) that will give me the folder size of multiple directories including all sub-files and folders in MB or GB and i WOULD like it to total the sizes. i do not need it to create an out.txt file with the results. on screen display would be fine.
any and all help is appreciated.
thank you,
NFBecause the command shell cannot handle floating point calculations the end-result could be many GB less than actual. Can you accept a batch script using VBS for the evaluations?
tahnk you
www.yerindebilgisayarservisi.usDusty,
i was afraid that would be a limitation with a .bat file.
Yes, i can accept a vbs for evaluations.
thank you,
NF
all,
after Dusty's post, i decided to give up on the .bat file and started looking at .vbs. with some help this is what i came up with, and it works to show me the total size of a directory, and then display total size of a second directory, how can i modify this to show me the size in MB or GB and give me a grand total at the end. honestly, i dont need the individual results, but only the grand total window with the results would be preferred.
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder("D:\FOLDERNAME") wscript.Echo "Size: " & objFolder.Size Set objFolder = objFSO.GetFolder("D:\FOLDERNAME") wscript.Echo "Size: " & objFolder.Size
of course replace FOLDERNAME with the name of the folder to view the size of.
I am at the infant stages of learning .vbs so any help would be appreciated.
thanks again all
NFCode: [Select]Set objFSO = CreateObject("Scripting.FileSystemObject")
Totalbytes = 0
' Using hard coded folder names
Set objFolder = objFSO.GetFolder("F:\Download\Alacarta\Programas")
Totalbytes = Totalbytes + objFolder.Size
Set objFolder = objFSO.GetFolder("F:\Download\App-install")
Totalbytes = Totalbytes + objFolder.Size
Set objFolder = objFSO.GetFolder("F:\Download\usenet")
Totalbytes = Totalbytes + objFolder.Size
wscript.echo "CRUDE Number Representation" wscript.echo wscript.echo "Total size = " & Totalbytes & " bytes" wscript.echo "Total size = " & (Totalbytes/1024) & " KB" wscript.echo "Total size = " & (Totalbytes/(1024*1024)) & " MB" wscript.echo "Total size = " & (Totalbytes/(1024*1024*1024)) & " GB" wscript.echo
' I suspect that you will not require to see the max number of decimal places ' so here's how to format the number ' change false to true and see what happens...
DecimalPlaces = 2 IncludeLeadingDigit = False UseParensForNegativeNumbers = False GroupDigits = False
wscript.echo "Formatted Number Representation" wscript.echo wscript.echo "Total size = " & Formatnumber((Totalbytes/1024), DecimalPlaces, IncludeLeadingDigit, UseParensForNegativeNumbers , GroupDigits) & " KB" wscript.echo "Total size = " & Formatnumber((Totalbytes/(1024*1024)), DecimalPlaces, IncludeLeadingDigit, UseParensForNegativeNumbers , GroupDigits) & " MB" wscript.echo "Total size = " & Formatnumber((Totalbytes/(1024*1024*1024)), DecimalPlaces, IncludeLeadingDigit, UseParensForNegativeNumbers , GroupDigits) & " GB"
Salmon Trout,
YOU ROCK!!!!!
exactly what i needed.
thank you very much.
now as I am at "infant level" when it comes to VB knowledge, can you suggest some good sites where i can learn more about VB scripting and how to do it all.
thanks,
NFQuote from: nuckinfutz on July 20, 2010, 02:07:24 PM can you suggest some good sites where i can learn more about VB scripting Anybody who is thinking of learning some VBScript should download and use the Microsoft Scripting help file, script56.chm which you can get here
http://www.microsoft.com/downloads/details.aspx?familyid=01592c48-207d-4be1-8a76-1c4099d7bbb9&displaylang=en
As for websites, there are MANY but these are some I have found useful:
This one is very good
Devguru main page
http://www.devguru.com/technologies/vbscript/home.asp
Devguru index of topics
http://www.devguru.com/Technologies/vbscript/quickref/vbscript_list.html
Microsoft VBScript reference:
http://msdn.microsoft.com/en-us/library/d1wf56tt%28VS.85%29.aspx
Another VBS reference:
http://www.adminscripteditor.com/syntax.asp?l=v&lim=1
Function reference
http://www.w3schools.com/VBscript/vbscript_ref_functions.asp
VBScript forum, FAQ etc
http://www.tek-tips.com/threadminder.cfm?pid=329
download coreutils if you can. then just simply use the du command Code: [Select]C:\test>du -sh c:\folder the -h OPTION means display the size in human readable format, ie MB, KB.I wrote this yesterday when this thread only had dusty's response, but decided to wait to post it until the OPsaid they could use a VBScript. It's similar in many ways to Salmon Trout's except that the folder names are accepted from the command line rather then hard coded. The "FormatSize" Function is a heavily modified version of the one in my File Library.
Also, I had completely forgotten that the Size property of a folder worked to recursively acquire the entire folder's size. I originally had a routine that was doing so MANUALLY, but I have modified it since.
Code: [Select]Public Function FormatSize(ByVal Bytes) Dim lookupprefix()
ReDim LookupPrefix(8) LookupPrefix(0) = " Bytes" LookupPrefix(1) = "KB" LookupPrefix(2) = "MB" LookupPrefix(3) = "GB" LookupPrefix(4) = "TB" LookupPrefix(5) = "PB" LookupPrefix(6) = "EB" LookupPrefix(7) = "ZB" LookupPrefix(8) = "YB"
currval = Bytes Do Until currval < 1024 currval = currval / 1024 countdiv = countdiv + 1 Loop
buildstr = Trim(FormatNumber(Round(currval, 2))) buildstr = buildstr + " " + Lookupprefix(countdiv)
FormatSize = buildstr
End Function
Set FSO = CreateObject("Scripting.FileSystemObject") For Each ARGUMENT in WScript.Arguments wpathname = argument WScript.Echo wpathname + ":" + FormatSize(FSO.GetFolder(wpathname).Size)
Next
|