Solved

total size of a directory

Posted on 2011-03-07
4
277 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 400 total points
Comment Utility
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 100 total points
Comment Utility
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
Comment Utility
Thnx it works in vbscript . i needed it for batch .but still OK
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

12 Experts available now in Live!

Get 1:1 Help Now