?
Solved

Display in one window, instead of several

Posted on 2006-07-10
9
Medium Priority
?
207 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
[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
  • 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 2000 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 1

Author Comment

by:johndarby
ID: 17076468
How do I truncate the numeric results to two decimal places?
0
 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Simple Linear Regression
Progress
Suggested Courses

770 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