Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
I need a DOS command/Batch file to get the
folder size alone.
Example C:\Sample1
Size is :457865Batch file must be DOS based.
Please help me on this.
Thanks

I don't think you'll hsve much luck getting 'folder' sizes in DOS.
=====================================
If at first you don't succeed, you're about average.M2

Yes.
I am new to batch file.
I surfed a lot for this.But i could not find
any solution.So can you help me to get a good solution for
this issue.

HEY M2, there is something that you can do for this, I just can't remember what it is, can you help me? It has something to do with %1 and theres a code at the end that shows the directories size.
I only Batch if possible, 2000 more lines of code, oh well.

thanks Batchfreak,
call a batch file like this:
test.cmd C:\samplebatch file:
echo %~z1It just shows the file Size.
But i need a batch file to show the folder
size.

There is no %~Z in DOS.
=====================================
If at first you don't succeed, you're about average.M2

trusp,
When you say dos, I guess you mean the
cmd.exe console on xp? If thats the case the
below script may work. not sure about hidden
files.
@echo off
if %1a==a echo No dir specified. Using current directory: %cd%.
set oldcd=%cd%
cd /d %1
set tz=
for /r %%A in (*) do set /a tz=tz + %%~zA
echo %tz%
cd /d %oldcd%--
Holla.

Yep, for /r doesn't like hidden files. Also with a large directory, probably c:\, you may run out of 32 or 64(probably unlikely) bit numbers depending on you version of windows. I'd rather let dir count up the files, including hidden and system files.
@ECHO OFF
SETLOCAL
:LOOP
SET FOLDER=
SET SHORT=
SET /P FOLDER=ENTER A FULLY SPECIFIED DIRECTORY/FOLDER PATH TO RETURN THE CONTENTS ^
SIZE IN BYTES. PLEASE SURROUND PATH NAMES THAT CONTAIN SPACE IN "DOUBLE QUOTES".
IF NOT DEFINED FOLDER GOTO LOOP
FOR /D %%A IN (%FOLDER%) DO SET SHORT=%%~SA
IF NOT EXIST %SHORT%\NUL GOTO LOOP
FOR /F "TOKENS=1-3 DELIMS= " %%A IN ('DIR /A /S %FOLDER%^|FIND /I "FILE(S)"') DO SET SIZE=%%C
SET SIZE=%SIZE:,=%
ECHO %FOLDER% IS %SIZE% BYTES IN SIZE
ENDLOCAL
PAUSEAlthough it seems like it would, it doesn't seem to matter if you specify a trailing backslash or not. Cmd doesn't seem to care if a directory name includes multiple backslashes.....

Judago,
That is a clever method.
I was splitting my hair thinking how to
ignore the intermediate File(s) summary info.The fact that - if you just parse all
File(s), the last one stays and the
intermediate output were automatically
ignored - never struck me :-(--
Holla.

Judago,
It was great. Thank you very much.
I got the size of the directory as
expected.
But i changed
SET /P FOLDER="C:\T System"
SET FOLDER="C:\T System"When i use SET /P FOLDER="C:\T System" .. It
displays C:\T System and on execution it not
moved to the next line of code.So i removed /P and it executed successfully.
Please tell me whether avoiding /P would be a
problem.???Then i need a clarification from you.
This output will not show the hidden files
size. Am i wright in this?Thanks
Trusp

trusp,
set /p takes the input from user.
so set /p folder="c:\t system" is waiting for
you to enter the folder name.
set folder="c:\t system" is absolutely fine
since you are interested in finding the size
of this folder always(as I understand).--
Holla.

If the operation will always be performed on a static directory some superfluous code can be removed. All this code does it check that the user selected valid input by testing the population of the variable and the existence of the target directory.
@ECHO OFF&SETLOCAL
FOR /F "TOKENS=1-3 DELIMS= " %%A IN ('DIR /A /S "c:\t system\"^|FIND /I "FILE(S)"') DO SET SIZE=%%C
SET SIZE=%SIZE:,=%
ECHO "c:\t system" IS %SIZE% BYTES IN SIZE
ENDLOCAL
PAUSE

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |