About You - Tools - Profile - Gallery

http://www.heelpbook.net/feed   Valid RSS (HeelpBook) - visit http://www.heelpbook.com/feed   http://www.heelpbook.com/feed


I need a DOS command/Batch file to get the folder size alone.


Size is :457865

Batch file must be DOS based.


I recently had a need to do this also.

Here is what I came up with.

It runs a DIR /S on the current directory and returns the second last line, which is the total size.

15976 File(s) 2,900,344,439 bytes

delims=)” splits it down the middle where the “)” character of “file(s)” is.
The last two SETs take off the word “bytes” and the leading spaces.

Size is :2900344439

All the echos except for the last one are for debugging.
It needs to be in a batch file for the variable names to work.

@For /F "tokens=*" %%a IN ('"dir /s /-c | find "bytes" | find /v "free""') do @Set summaryout=%%a
@Echo %summaryout%
@For /f "tokens=1,2 delims=)" %%a in ("%summaryout%") do @set filesout=%%a&set sizeout=%%b
@Echo %filesout%
@Echo %sizeout%
@Set sizeout=%sizeout:bytes=%
@Echo %sizeout%
@Set sizeout=%sizeout: =%
@Echo Size is :%sizeout%

Hope it does the trick for you.

SOLUTION (Without Echoes)

@Echo off
For /F "tokens=*" %%a IN ('"dir /s /-c | find "bytes" | find /v "free""') do @Set summaryout=%%a
REM @Echo %summaryout%
For /f "tokens=1,2 delims=)" %%a in ("%summaryout%") do @set filesout=%%a&set sizeout=%%b
REM @Echo %filesout%
REM @Echo %sizeout%
Set sizeout=%sizeout:bytes=%
REM @Echo %sizeout%
Set sizeout=%sizeout: =%
REM @Echo Size is :%sizeout%

Note: find /V is used to select all the the lines NOT containing the word/string specified.



Facebook Twitter Email Plusone Linkedin Stumbleupon Delicious Digg
© 2011 - 2013 HeelpBook - Today is: 28/3/2017 Last updated: June 10, 2015 at 15:57 pm Get helped -
+ +