Search : in
By :

Dos Command/Batch file to find a folder size

Last answer on May 15, 2009 9:53:51 am BST trusp, on Dec 4, 2008 11:41:47 am GMT 
 Report this message to moderators

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

Configuration: Windows XP
Safari 525.13

Best answers for « Dos Command/Batch file to find a folder size » in :
[Shell]Create a file having a specific size ShowShell]Create a file having a specific size The dd command allows you to create "empty" file of desired size, creating these arbitrary heavy files, may be useful for testing purposes. Use command below: dd if=/dev/zero of=file_to...
How to use the tar command ShowHow to use the tar command Archiving files with “tar” Archiving folder (or directory) with “tar” Unpacking file with tar Unpack the file with tar Unpacking specific files with "tar" Archiving files with “tar” The "tar"...
Basic MS-Dos commands ShowBasic MS-Dos commands Intro The command prompts: Intro Here is a list of basic commands that you can use in a DOS prompt (e.g. a using a boot disk). To have additional information about these commands, type /? after entering the...
Download Locked Files Wizard (ex CopyLock) ShowA program, a folder or a fil used by a process can't be moved or erased. Locked Files Wizard (LFW) is a wizard allowing to move, delete or rename a file or a folder, even if it's used by a process. This program also allows to stop running process...
MS DOS Files and directories ShowFiles in MS DOS In a computers data is stored in files. When you run a program, MS-DOS processes the data stored in the file and passes it to the system. In MS-DOS a file can be any size, however the file name is more restricted, it can only have...
Operating Systems - MS-DOS - Commands ShowCommand Description dir lists the contents of a folder cd changes folder cd .. parent folder md or mkdir creates a new folder deltree deletes a folder and all sub-folders copy, xcopy copies...

1

Boris, on Dec 4, 2008 3:51:02 pm GMT

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

Reply to Boris

2

Boris, on Dec 4, 2008 3:52:26 pm GMT
  • +2

Run the batch file passing the name of the directory you want to get the size of i.e.
dirsize c:\temp

Reply to Boris

3

Boris, on Dec 4, 2008 4:03:05 pm GMT
  • +4

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

Reply to Boris

5

Methical, on Apr 17, 2009 7:54:19 am BST
  • +1

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 to Methical

4

trusp, on Dec 5, 2008 9:50:40 am GMT
  • +2

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...

Reply to trusp

6

 Little Helper, on May 15, 2009 9:53:51 am BST
  • +2

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 to Little Helper