Solved

Batch - size of directory question.

Posted on 2007-03-29
6
1,494 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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