Batch file to display directory size


I want to modify this script. I can't get it to accept wildcard charcters:

@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

It is in a batch file called dirsize and is called like so:

dirsize c:\folder

I want it to check the folder sizes for me. This one here is an example, the cache in firefox:

dirsize C:\users\%username%\AppData\Local\Mozilla\Firefox\*.default\Cache

It returns the value 0.

But if I go

dirsize C:\users\%username%\AppData\Local\Mozilla\Firefox\sr1znnb4.default\Cache

It works and I get the value 55322 returned.

Best Solution

PowerShell makes this easy, of course:

    (gci . -Recurse | Measure-Object -Property Length -Sum).Sum

And PowerShell is already installed on Windows 7. Get on the bandwagon! :-)

Also, C:\users\%USERNAME%\AppData\ isn't a reliable way of finding AppData. Try %APPDATA% (or $env:APPDATA in PowerShell).