Solved

Display in one window, instead of several

Posted on 2006-07-10
9
201 Views
Last Modified: 2010-04-17
The script below displays the size of immediate sub-directories within c:\documents and settings. How may I cause it to display in one windows, instead of one-each for each result?

Dim objFSO, objFolder, objSub, nTotal
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\documents and settings")

nTotal = 0
'loop through each subfolder, displaying its size
For Each objSub In objFolder.SubFolders
      Wscript.Echo "Folder " & objSub.Name & " is " & ((objSub.Size)/1048576) _
      & " MB"
      ntotal = nTotal + ((objSub.Size)/1048576)
Next

Wscript.Echo "Total for all folders:" & nTotal & " MB"
0
Comment
Question by:johndarby
  • 4
  • 4
9 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 17075983
Hmm, I wonder if a for instead of a foreach work...
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 500 total points
ID: 17076096
Try this:

nTotal = 0
'loop through each subfolder, displaying its size
Dim displayText
displayText = ""
For Each objSub In objFolder.SubFolders
     'Wscript.Echo "Folder " & objSub.Name & " is " & ((objSub.Size)/1048576) & " MB"
     displayText = displayText & Chr(10) & "Folder " & objSub.Name & " is " & ((objSub.Size)/1048576) & " MB"
     ntotal = nTotal + ((objSub.Size)/1048576)
Next

Wscript.Echo displayText & Chr(10) & Chr(10) & "Total for all folders:" & nTotal & " MB"
0
 
LVL 1

Author Comment

by:johndarby
ID: 17076413
Works like a charm...thank you!
0
 
LVL 1

Author Comment

by:johndarby
ID: 17076468
How do I truncate the numeric results to two decimal places?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 15

Expert Comment

by:bpmurray
ID: 17076972
Use FormatNumber ...
& " is " & FormatNumber((objSub.Size)/1048576, 2) & " MB"   ' 2 = number of decimals
0
 
LVL 1

Author Comment

by:johndarby
ID: 17077117
That works wonderfully, as well!
I am going to create another issue to ask how to make a simple user interface to allow a user to enter a hostname and sharename\path to extend the function of this script.
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17077165
Actually, I've never done any major dialog stuff, so I don't know if you can do it in one dialog, but this will certainly work:
  Dim Host, Share
  Host = InputBox("Enter host name")
  Share= InputBox("Enter share name & path")

0
 
LVL 1

Author Comment

by:johndarby
ID: 17077220
Thanks bpmurray! I am unsre how exactly to add these, but I am working on it now!
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17077246
Have fun! Glad I could help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now