Solved

Batch - size of directory question.

Posted on 2007-03-29
6
1,520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

626 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