Dir/Subdir sizes to txt

Microsoft Windows xp professional w/serv...
February 22, 2010 at 12:39:40
Specs: Windows XP
I found the following batch on this forum and it works great until it hits an empty dir. It then reports File Not Found (makes sense on an empty dir) and writes the previous dir size to output. Is there a way to output something like "0 bytes" when it hits an empty dir?

@echo off
for /F "tokens=*" %%D in ('dir %1 /S/B/AD') do call :show "%%D"
goto :EOF
dir /a-d "%*" | find /i "bytes" | find /i /v "free">thedirsize
set /p size=<thedirsize
echo %* %size%>>dirsizes.txt
goto :eof

See More: Dir/Subdir sizes to txt

Report •

February 22, 2010 at 13:54:20
I wrote a better one a few months ago. But I can't find it. LOL So I wrote another one. I think this qualifies as reinventing the wheel.

@echo off > %TEMP%\newfile & setLocal enableDELAYedeXpansion

set home=%CD%

for /f "tokens=* delims= " %%a in ('dir/b/s/ad') do (
set Z=0
pushd "%%a"
for /f "tokens=* delims= " %%i in ('dir/b/a-d 2^> nul') do (
set /a Z+=%%~Zi
>> %TEMP%\newfile echo !Z! bytes in %%a

move /y %TEMP%\newfile %home%\sizelist

Helping others achieve escape felicity


Report •

February 22, 2010 at 13:58:38
Easiest method:
echo 0 bytes>thedirsize
dir /a-d "%*" | find /i "bytes" | find /i /v "free">thedirsize

Report •

February 22, 2010 at 15:41:34
@M2 thats exactly what I needed thanks!

@Razor2.3 thanks for your help as well

Report •

Related Solutions

Ask Question