SCENARIO
Hello,
I need a DOS command/Batch file to get the folder size alone.
Example:
C:\Sample1 Size is :457865
Batch file must be DOS based.
SOLUTION
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.
SOURCE | LINK | LANGUAGE | ENGLISH |