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

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

15 replies

Best answer
Posts
4
Registration date
Wednesday December 3, 2008
Last seen
December 5, 2008
- Dec 5, 2008 at 04:50 AM
45
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 1677 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! :)
Awesome!
Very good!!!!!! tks
6
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
Posts
1
Registration date
Wednesday January 20, 2010
Last seen
January 20, 2010
- 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

Example:
dirsize c:\temp

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

Any suggestion?
Thanks

Regards,
becks
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
That's good man!
3
Thank you
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
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
2
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
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
Posts
1
Registration date
Tuesday January 5, 2010
Last seen
January 6, 2010
- Jan 6, 2010 at 01:45 AM
1
Thank you
Great scripts.. anyway could we exclude the folder also?

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