Obtaining total directory size at command line (cntd.)


D

doofus

@echo off
rem start dirsize.exe.lnk

setlocal
for /f "tokens=*" %%a in ( 'dir /w /s %1 ^| findstr "File(s)"') do @set
info=%%a
echo Directory %1 - %info%



Hi,

When I run the foregoing code in a file dirsize1.bat, I used to get the
size of the entire directory including subdirectories, recursively.

Now, instead, I get "The directory name is invalid", no matter what.

I was given the code on this newsgroup, and never understood how it
worked.

http://tinyurl.com/hx27 --link to original post on google groups.

I've discovered that if I go 'dir /w /s . | findstr "File(s)"', I also
get this same error message.

I recall increasing the environment size some time ago in order to get
another dos utility to work. Would that have made any difference?

I'm posting this here is the hope that one of you kind experts might be
able to see right away what the problem is or suggest an alternative.

The batch file was very useful, but if I can't get it to work, I'll just
find a work around.

I just don't know what I've done wrong.

Will appreciate any help. Yours truly is completely mystified.

My OS is Win2k.

Thanks.
 
Ad

Advertisements

R

Ritchie

doofus said:
@echo off
rem start dirsize.exe.lnk

setlocal
for /f "tokens=*" %%a in ( 'dir /w /s %1 ^| findstr "File(s)"') do @set
info=%%a
echo Directory %1 - %info%
The "set" and "info=%%a" have been split by a CR/FL. Avoid line wrapping
altogether by using shorter lines:-

@echo off & setlocal ENABLEEXTENSIONS
for /f "tokens=*" %%a in ('dir/w/s %1 ^|findstr "File(s)"') do (
set info=%%a
)
echo Directory %1 - %info%
 
D

doofus

Ritchie said:
The "set" and "info=%%a" have been split by a CR/FL. Avoid line
wrapping altogether by using shorter lines:-

@echo off & setlocal ENABLEEXTENSIONS
for /f "tokens=*" %%a in ('dir/w/s %1 ^|findstr "File(s)"') do (
set info=%%a
)
echo Directory %1 - %info%
C:\>type dirsize1.bat
@echo off
rem start dirsize.exe.lnk

setlocal ENABLEEXTENSIONS
for /f "tokens=*" %%a in (
'dir /w /s %1 ^| findstr "File(s)"') do (
@set info=%%a
)
echo Directory %1 - %info%


C:\>dirsize1 c:\backup
The directory name is invalid.
Directory c:\backup -



Thanks for the quick reply. I changed it to the above, but it still
ain't workin'.

I'm sorry about that.
 
R

Ritchie

doofus said:
Thanks for the quick reply. I changed it to the above, but it still
ain't workin'.
I've only been able to replicate your issue with the first batch file you
posted. Did you try the example I posted? Although your second example
works on my Win2000 machine, the position of your CR/LF's are still
questionable, especially if running under NT4. Does it work on another
machine?

If you still can't get to work, turn echo on and post the output. You might
also want to rename it using a .cmd extension.
 
D

doofus

Ritchie said:
I've only been able to replicate your issue with the first batch file
you posted. Did you try the example I posted? Although your second
example works on my Win2000 machine, the position of your CR/LF's are
still questionable, especially if running under NT4. Does it work on
another machine?

If you still can't get to work, turn echo on and post the output. You
might also want to rename it using a .cmd extension.
Thanks for checking this over for me. Here's what I've got so far. I'm
starting to lose hope. I think there's something deeply wrong with my
system. Everything else is working OK, so far. This code used to work
fine on this machine.


C:\>dir c:\backup
Volume in drive C has no label.
Volume Serial Number is 3C43-A300

Directory of c:\backup

24/07/2003 16:04 <DIR> .
24/07/2003 16:04 <DIR> ..
24/07/2003 04:29 740 backup.bat
23/07/2003 19:24 1,297 backup.txt
23/07/2003 19:24 15,872 backup.xls
24/07/2003 14:52 <DIR> demo
24/07/2003 16:06 1,061 e.txt
24/07/2003 04:52 2,185 error.txt
24/07/2003 04:23 192 excluded.txt
24/07/2003 14:19 434 here.txt
24/07/2003 04:52 4,047,529 out.txt
24/07/2003 13:49 624 system.txt
23/07/2003 19:20 23 test.txt
10 File(s) 4,069,957 bytes
3 Dir(s) 7,587,094,528 bytes free

C:\>type dirsize1.cmd
@echo on & setlocal ENABLEEXTENSIONS
for /f "tokens=*" %%a in ('dir/w/s %1 ^|findstr "File(s)"') do (
set info=%%a
)
echo Directory %1 - %info%


C:\>dirsize1.cmd c:\backup

C:\>for /F "tokens=*" %a in ('dir/w/s c:\backup |findstr "File(s)"') do
(set inf
o=%a )
The directory name is invalid.

C:\>echo Directory c:\backup -
Directory c:\backup -
C:\>dir/w/s c:\backup |findstr "File(s)"
The directory name is invalid.

C:\>dir/w/s c:\backup > here.txt

C:\>type here.txt
Volume in drive C has no label.
Volume Serial Number is 3C43-A300

Directory of c:\backup

[.] [..] backup.bat backup.txt backup.xls
[demo] e.txt error.txt excluded.txt here.txt
out.txt system.txt test.txt
10 File(s) 4,069,957 bytes

Directory of c:\backup\demo

[.] [..] DirTreeSpace.cmd
1 File(s) 131 bytes

Total Files Listed:
11 File(s) 4,070,088 bytes
5 Dir(s) 7,587,094,528 bytes free

C:\>findstr "File(s)" here.txt
10 File(s) 4,069,957 bytes
1 File(s) 131 bytes
11 File(s) 4,070,088 bytes

C:\>
 
R

Ritchie

doofus said:
The directory name is invalid.
Try running CHKDSK (see its commandline options first), or the Windows Explorer
equivalent ('Check Now' button) on your drive(s). Don't forget to backup!
 
Ad

Advertisements

Joined
Nov 24, 2011
Messages
1
Reaction score
0
Make it easy on yourself... Install Cygwin (free) and use Linux's du command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top