Report

Dos Command/Batch file to find a folder size [Solved]

Ask a question trusp 4Posts Wednesday December 3, 2008Registration date December 5, 2008 Last seen - Latest answer on Dec 18, 2012 10:26PM
Hello,
I need a DOS command/Batch file to get the folder size alone.
Example C:\Sample1
Size is :457865
Batch file must be DOS based.
Please help me on this.
Thanks
See more 
Helpful
+44
moins plus
Hi Boris,

Thank you very much for your respond.
I copied this script and executed as you specified. But not got any solution.
The following was been displayed in CLI.
C:\>Test.cmd C:\Sample
'selLocal' is not recognized as an internal or external command,
operable program or batch file.
Missing operator.
Missing operator.
Missing operator
....
Size is: !value!

So I put @echo on and the CLI executed as shown below:
C:\>Test.cmd C:\Sample

C:\>selLocal EnableDelayedExpansion
'selLocal' is not recognized as an internal or external command,
operable program or batch file.

C:\>set /a value=0

C:\>FOR /R C:\Sample %I IN (*) DO set /a value=!value!+%~zI

C:\>set /a value=!value!+3064
Missing operator.

C:\>set /a value=!value!+2672
Missing operator.

C:\>set /a value=!value!+6135
Missing operator.

C:\>set /a value=!value!+5
Missing operator.

C:\>set /a value=!value!+2
Missing operator.
Size is: !value!

Please Help me out in this.
Say where I made mistake ?
I need this very urgent. So please...
Little Helper- May 15, 2009 04:53AM
It's a simple spelling error: He meant "setlocal".

Google could have told you this, try googling: sellocal batch script

In the first line, google will say "Did you mean setlocal?".

Have fun.
Reply
popsi- Dec 19, 2009 06:16AM
awesome script.. thanks a lot mate..
Reply
r4k4- Sep 21, 2011 04:38AM
Super Script Dude! :)
Awesome!
Reply
Chao Lin- Dec 18, 2012 08:38PM
Very good!!!!!! tks
Reply
Add comment
Helpful
+6
moins plus
For large directories, it might be better to list in k or Mb to avoid number overflow...

@echo off
setLocal EnableDelayedExpansion
set /a value=0
set /a sum=0
FOR /R %1 %%I IN (*) DO (
set /a value=%%~zI/1024
set /a sum=!sum!+!value!
)
@echo Size is: !sum! k
Methical- Apr 17, 2009 02:54AM
Hi mate, cheers for the script
But could you adapt it to hold wildcard characters such as * and ?

I'm trying to get the size of the firefox cache in vista to add into my cleanup script. Since the profile which is "..\xxxxxx.default\cache\" and xxxxxx is different on all computers, I would like to use wildcard characters plz..

dirsize C:\Users\Methical\AppData\Local\Mozilla\Firefox\sr1znn4b.default\Cache

dirsize %localappdata\Mozilla\Firefox\*.default\Cache
Reply
becks2000 1Posts Wednesday January 20, 2010Registration date January 20, 2010 Last seen - Jan 20, 2010 09:03PM
Hi Boris,

It a nice script.. I am quite new to batch file coding.. After studying the batch file, I unable to edit to my requirements.

I need to display the folder name and the folder size in bytes(up to 200gb) and number of files in the folder. As I need to print it to a log file

Example:
dirsize c:\temp

Size of c:\temp is : 123,345,344 bytes
Number of files : 200

Any suggestion?
Thanks

Regards,
becks
Reply
charlie2013- Dec 18, 2012 10:17PM
Hi Boris ,

I have a problem of access denied on some folders in c: \ document and settings \ for different users on my network , do u have any consideration correlated your script??

[]'s

Charlie Sheen
Reply
Mandarilho- Dec 18, 2012 10:26PM
That's good man!
Reply
Add comment
Helpful
+3
moins plus
Hi,

You can do this with a batch file something like this:

@echo off
selLocal EnableDelayedExpansion
set /a value=0
FOR /R %1 %%I IN (*) DO set /a value=!value!+%%~zI
@echo Size is: !value!

HTH
Boris
Boris- Dec 4, 2008 10:52AM
Run the batch file passing the name of the directory you want to get the size of i.e.
dirsize c:\temp
Reply
tommyboy- Sep 16, 2010 03:47PM
type, selLocal EnableDelayedExpansion should read
setLocal EnableDelayedExpansion
Reply
Add comment
Helpful
+2
moins plus
The original command for doing that on *nix based systems was 'du'. You can get a Win32 port of the GNU file utils from
http://sourceforge.net/projects/unxutils/
http://unxutils.sourceforge.net/

As an example, using the included utils you can get a list of the directory sizes within the current one by running
find . -maxdepth 1 -exec du -sh \"{}\" \;

Sysinternals have released a lesser clone of the *nix version which is available from
http://technet.microsoft.com/en-us/sysinternals/bb896651.aspx
Add comment
Helpful
+1
moins plus
Great scripts.. anyway could we exclude the folder also?

example: populate size inside %systemroot%\system32\ but exclude folder "drivers".
Add comment

Members get more answers than anonymous users.

Being a member gives you detailed monitoring of your requests.

Being a member gives you additional options.

Not a member yet?

sign-up, it takes less than a minute and it's free!