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

Ask a question trusp 4Posts Wednesday December 3, 2008Registration date December 5, 2008 Last seen - Last answered on Dec 18, 2012 at 10:26 PM by Mandarilho
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.
See more 
plus moins
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...
Was this answer helpful?  
Little Helper- May 15, 2009 at 04:53 AM
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.
popsi- Dec 19, 2009 at 06:16 AM
awesome script.. thanks a lot mate..
r4k4- Sep 21, 2011 at 04:38 AM
Super Script Dude! :)
Chao Lin- Dec 18, 2012 at 08:38 PM
Very good!!!!!! tks
plus moins
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 at 02:54 AM
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
becks2000 1Posts Wednesday January 20, 2010Registration date January 20, 2010 Last seen - Jan 20, 2010 at 09:03 PM
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

dirsize c:\temp

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

Any suggestion?

charlie2013- Dec 18, 2012 at 10:17 PM
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??


Charlie Sheen
Mandarilho- Dec 18, 2012 at 10:26 PM
That's good man!
plus moins

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!

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

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
plus moins
Great scripts.. anyway could we exclude the folder also?

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

Member requests are more likely to be responded to.

Members can monitor the statuses of their requests from their account pages.

A CCM membership gives you access to additional options.

Not a member yet?

Sign up now. It takes less than a minute and is completely free!