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

trusp 4 Posts Wednesday December 3, 2008Registration date December 5, 2008 Last seen - Dec 4, 2008 at 06:41 AM - Latest reply:  Mandarilho
- Dec 18, 2012 at 10:26 PM
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 

15 replies

Best answer
trusp 4 Posts Wednesday December 3, 2008Registration date December 5, 2008 Last seen - Dec 5, 2008 at 04:50 AM
Thank you
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...

Thank you, trusp 45

Something to say? Add comment

CCM has helped 1884 users this month

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 > Little Helper - Dec 19, 2009 at 06:16 AM
awesome script.. thanks a lot mate..
Super Script Dude! :)
Very good!!!!!! tks
Thank you
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
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 1 Posts 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?

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
That's good man!
Thank you

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!

Run the batch file passing the name of the directory you want to get the size of i.e.
dirsize c:\temp
type, selLocal EnableDelayedExpansion should read
setLocal EnableDelayedExpansion
Thank you
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
syafaat 1 Posts Tuesday January 5, 2010Registration date January 6, 2010 Last seen - Jan 6, 2010 at 01:45 AM
Thank you
Great scripts.. anyway could we exclude the folder also?

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