Solved

Display in one window, instead of several

Posted on 2006-07-10
9
202 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 109
control image tags in a string ? 12 111
How to get time difference in minutes and seconds only between 2 dates 2 26
T-SQL:  Sigh---Boy, this is fun.... 12 34
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…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

21 Experts available now in Live!

Get 1:1 Help Now