Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file that returns folder size

I'm having space issues on my Vista machine and need to figure out what's taking up so much space.

I would like to write a simple batch file that returns all folders under C: and the size of each folder.

The dir command doesn't appear to return folder size.

Unfortunately we don't have admin rights and can't install a third party application and we have other users in our group that also need this information.

like image 619
Paul Wall Avatar asked Dec 23 '10 13:12

Paul Wall


People also ask

How do I get a list of folder sizes?

User Properties For the most detailed view of your folder sizes, you'll have to use the Properties feature. To do so, right-click on a folder and select Properties at the bottom of the menu. A new window will open up and show you some additional info on your folder.

What does %1 mean in a batch file?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.

What does %% mean in batch script?

Use a single percent sign ( % ) to carry out the for command at the command prompt. Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required.


2 Answers

I'd have a look at this thread for some clues as to how to achieve the directory size:

Batch File To Display Directory Size

Otherwise:

dirsize:

@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 %CD%:!sum! k

AllDirSize:

echo off
set WORKING_DIRECTORY=%cd%
    for /f "delims=" %%a in ('dir /a:D /D /B /S') do (  
            echo off
            cd %%a
            "%WORKING_DIRECTORY%"\dirsize "%%a"
            cd %WORKING_DIRECTORY%
) 

Use it: ALLDIRSIZE > C:\temp\FileContainingFolderSizes.txt

Which is taken from the excellent Richard Bishop testing forums: http://www.bish.co.uk/forum/index.php?topic=58.0

like image 61
Mark Mayo Avatar answered Sep 20 '22 12:09

Mark Mayo


Not exactly answering your question, but if you have GUI access I'd suggest using TreeSize: http://www.jam-software.com/freeware/index.shtml

If you prefer command line use du command from Unix utils: http://unxutils.sourceforge.net/

like image 33
MK. Avatar answered Sep 22 '22 12:09

MK.