GetSize

A command-line utility for recursively getting directory size.

Depends upon: Windows, Powershell

Preparation

  1. Create a folder on your computer to place utilities into. For the purpose of this guide, I will use the path: "C:\_DevBin"
  2. Ensure you have Powershell correctly installed and you have the correct execution permissions set. You can find out the latter when attempting to execute the file on a restricted session.

GetSize code

@echo off
powershell -noprofile -command "switch((ls -r|measure -s Length).Sum) { {$_ -gt 1GB} { '{0:0.0} GiB' -f ($_/1GB); break; }; {$_ -gt 1MB} { '{0:0.0} MiB' -f ($_/1MB); break; }; {$_ -gt 1KB} { '{0:0.0} KiB' -f ($_/1KB); break; } default { \"$_ bytes\"; } }"

Open a new notepad window, paste in the sample code and save the document as C:\_DevBin\GetSize.bat

Make the tool accessable from anywhere

Once you have a local folder with the GetSize file in, open your system's Environment Variables dialog. This can vary from different versions of Windows, so you may need to check online for the exact method.

When you have the Environment Variables dialog open, edit the PATH System Environment Variable, and add to the start:

C:\_DevBin;

This will make all binaries and executables in the _DevBin folder available from any command prompt.

Test out your utility!

Open a new command prompt window and navigate to a folder that contains sub-folders. Type GetSize and hit enter - the utility will then calculate the total size of the directory and report it back on completion!

GetSize example

Download the Utility

Here's one I made earlier - a download containing the code and a quick readme.

Download Download