Solved

Batch - size of directory question.

Posted on 2007-03-29
6
1,474 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
Comment Utility

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

0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 250 total points
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

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

Author Comment

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

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

9 Experts available now in Live!

Get 1:1 Help Now