Solved

Display in one window, instead of several

Posted on 2006-07-10
9
206 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 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Make the most of your online learning experience.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

691 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