Solved

Batch - size of directory question.

Posted on 2007-03-29
6
1,502 Views
Last Modified: 2012-06-27
Is it possible to detect size of directory and if so what would be the syntax to do that with batch file and echo out the result ot text file?
0
Comment
Question by:lescluster
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:maphew
ID: 18820092

dir [dir name] | find "File(s)" > results.txt

0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 250 total points
ID: 18820145
The following will allow you to grab the output of a command like above into a variable if needed or to format how you want.  The -c on the dir command turns off the commas in the output.

@echo off
cd \testdir
for /f "tokens=3" %%a in ('dir /-c ^| find "File(s)"') do set sizeofdir=%%a
echo Size of dir %cd% is %sizeofdir%

If you want the total of all subdirectories then add a /s after the -c in the dir command - the find filter will pull out all the directory totals but the one that ends up setting the sizeofdir variablt in the end is the last one which is the grand total.

hth

Steve
0
 

Author Comment

by:lescluster
ID: 18820212
Steve
It appears that all I am getting is the size of the file in that directory but not in the subfolders. I have subfolders in the misc directory that I would like to include in the count.  I am using your script like that:
@echo off
cd \documents and settings\misc
for /f "tokens=3" %%a in ('dir /-c ^| find "File(s)"') do set sizeofdir=%%a
echo Size of dir %cd% is %sizeofdir%

Thanks
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:lescluster
ID: 18820389
Steve
I figure that out -  had to use \s switch -  thanks much for your help
0
 

Author Comment

by:lescluster
ID: 18820404
duh - just notice you were already talking about /s -  need some sleep.
Thanks again
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18821749
Haha, no problem.  glad to help, was just a quick answer while shutting down PC for the night anyway...
Steve
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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