Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch - size of directory question.

Posted on 2007-03-29
6
Medium Priority
?
1,522 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 1000 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

704 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