Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Total Size of files in a folder

Status
Not open for further replies.

GregNVMC

IS-IT--Management
Jul 8, 2003
19
GB
Hi,

Please can someone tell me if it's possible to use VBS to search through a folder and find the total size of the files in just that folder and not all of the subfolders?

I've tried using:

Code:
dim fso, f, filesize1

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("S:\")
Set colFiles = F.Files
for each file in colfiles

filesize1=file.size
wscript.echo formatNumber((filesize1/1048576), 0) & " Mb"

next
This displays each of the file sizes, but I want to know how to add these values together, rather than display them seperately? This way I can workout the total size of all the files.

Thanks in advance.

Greg
 
Hey!

Your code should look like this:

dim fso, f, filesize1
dim totalsize '--> added

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("S:\")
Set colFiles = F.Files
for each file in colfiles

totalsize = totalsize + file.size '--> modified
'this will get the size of all previos files and will add the size of the current file

next
wscript.echo formatNumber((totalsize/1048576), 0) & " Mb"

Gregor
hydralisk@email.si


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top