Computing.Net > Forums > Programming > Dos Command/Batch file to find a fo

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Dos Command/Batch file to find a fo

Reply to Message Icon

Name: trusp
Date: December 5, 2008 at 20:28:14 Pacific
OS: MS Windows XP
CPU/Ram: Intel DUO
Product: Ms / E6550
Comment:

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.

Please help me on this.
Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: December 5, 2008 at 21:36:28 Pacific
Reply:

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


0

Response Number 2
Name: trusp
Date: December 5, 2008 at 21:44:50 Pacific
Reply:

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.


0

Response Number 3
Name: BatchFreak
Date: December 5, 2008 at 21:48:13 Pacific
Reply:

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.


0

Response Number 4
Name: trusp
Date: December 5, 2008 at 21:54:49 Pacific
Reply:

thanks Batchfreak,

call a batch file like this:
test.cmd C:\sample

batch file:
echo %~z1

It just shows the file Size.
But i need a batch file to show the folder
size.



0

Response Number 5
Name: trusp
Date: December 5, 2008 at 22:00:32 Pacific
Reply:

Sorry call the batch file as
test.cmd C:\sample\sam.txt
So it displays
C:\>echo 23040
23040


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: December 6, 2008 at 21:20:17 Pacific
Reply:

There is no %~Z in DOS.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: Holla
Date: December 7, 2008 at 08:43:11 Pacific
Reply:

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.


0

Response Number 8
Name: Judago
Date: December 7, 2008 at 20:58:26 Pacific
Reply:

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
PAUSE

Although 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.....


0

Response Number 9
Name: Holla
Date: December 7, 2008 at 21:24:02 Pacific
Reply:

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.


0

Response Number 10
Name: trusp
Date: December 9, 2008 at 23:41:46 Pacific
Reply:

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


0

Response Number 11
Name: Holla
Date: December 10, 2008 at 00:45:48 Pacific
Reply:

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.


0

Response Number 12
Name: Judago
Date: December 10, 2008 at 02:51:39 Pacific
Reply:

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



0

Response Number 13
Name: trusp
Date: December 10, 2008 at 03:02:30 Pacific
Reply:

Judago,

Thank u very much for your support in
this issue...
it worked fine...

Trusp


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Dos Command/Batch file to find a fo

Batch File to find files www.computing.net/answers/programming/batch-file-to-find-files/17076.html

Batch File to Create a Shortcut www.computing.net/answers/programming/batch-file-to-create-a-shortcut/13374.html

A batch file to kill a process www.computing.net/answers/programming/a-batch-file-to-kill-a-process/12884.html