?
Solved

total size of a directory

Posted on 2011-03-07
4
Medium Priority
?
294 Views
Last Modified: 2012-05-11
Hi,
I need a batch to run and check if a total size of a c:\sample (subdirectory and files included) is less than 3 mb in total then delete SAMPLE folder and it`s subdirectories and files within it.
0
Comment
Question by:drtopserv
4 Comments
 
LVL 16

Accepted Solution

by:
santoshmotwani earned 1600 total points
ID: 35055178
wscript.exe DELETE.vbs

Dim objFD
Set objFD = CreateObject("Scripting.FileSystemObject")
Set objSelectedFolder = objFD.GetFolder("path to sample folder")
Set colSubfolders = objSelectedFolder.SubFolders
For Each objSubfolder In colSubfolders
If objSubfolder.Size < 3000000 Then
objSubfolder.Delete True
End If
Next

ref :http://www.computing.net/answers/programming/batch-file-to-delete-folders-less-than-3mb/22099.html
0
 
LVL 10

Assisted Solution

by:wls3
wls3 earned 400 total points
ID: 35058583
The following scripting guys link will help you get folder sizes:
http://technet.microsoft.com/en-us/library/ff730945.aspx
0
 

Author Closing Comment

by:drtopserv
ID: 35224822
Thnx it works in vbscript . i needed it for batch .but still OK
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35227700
There are a couple of free utilities you could use from a BAT script to do this, like:

http://technet.microsoft.com/en-us/sysinternals/bb896651.aspx
http://www.gammadyne.com/cmdline.htm#sizeof

It's pretty hard to do with just BAT commands and no helper utility.  The real problem with doing it in BAT is that numbers in BAT are limited to a maximum integer of 2147483648.  That's 2GB.  So if you were to try and process folders that had sizes that exceed that number then weird stuff starts to happen with BAT arithmetic.

If you want to assume that no folders ever exceed that, then using one of those utils in a BAT file could work, if you want help with that let me know.

~bp
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Loops Section Overview
Screencast - Getting to Know the Pipeline

839 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