Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Can a batch file count. I am in a DOS 6.22 class, and was given the assignment “Create a batch file that when invoked, makes a file that contains subdirectories and then counts them. This needs to be from a drive that has several subdirectories on it." I can pipe a 'DIR *. ' to a file, but how can I count the lines? Can I count line feeds or am I thinking the wrong way. Any thoughts on this would be appreciated.

Hi there
I'm actually making a calculator based on batch files and you're asking me if a batch file can count??? hahahahbtw, in your case -- IF I have understood you well -- we don't need to actually count.
But letme clear something... When you said "makes a file that contains subdirectories" , you meant "contains subdirecoties NAMES", is that it?Ok, if that's it:
This will put the directories to out.txt
numbers aren't part of it.::sample.bat
01. dir/s/b/ad > out.txt
02. dir/s/ad |find "directory free"> out2.txt
03. echo.>> out2.txt
04. dateout.bat
05. echo SET LINES=%%4> enter.bat
06. call out.bat
07. del out.bat
08. del enter.bat
09. del out2.txt
10. echo NUMBER OF DIRs and SUBDIRs = %LINES%'This depends on the dos language. This is for english dos. I'm not sure of lines 2 and 4
I'm actually not sure about the words "directory" and "free"... type "dir" and see the last line, then you'll see the right words there (its case sensitive)The problem is that MY dos isn't in english, but I think that one will work
Was that what you wanted???
Please keep me informed!-- Secret_Doom --
email: secret_doom@hotmail.com

Thanks for the fast response, I will try your creation in a few minutes after Hardware Shuffle to DOS PC. The instructions were as you saw, just as the instructor posted for my on-line DOS 6.22 class. The class is given by a true state funded community college in Salem, Oregon, USA. The instructor is a young woman who may not even have been in elementary school when I had my KayPro CP/M suitcase. At least DOS is not dead here in the backwoods of Oregon. I will report back, but not soon. Thanks Again

to Doom:
Yes, this creates a list of the directories,
but at the end the %LINES% is empty in the echo. I am going to step thru it one line at a time. Really neat work you did!

Wow! Good trick Laurence. Hadn't thought about that before...
So hey Matt, that all can be done by these two lines:
dir/b/s/ad > out.txt
dir/b/s/ad |FIND /c ":\"If you still what to use my first example:
I said I weren't sure about words "directory" and "free" at lines 2 and 4
Maybe they're wrong.Type "dir" and check last line. They will be there.
-- Secret_Doom --

![]() |
store processing result i...
|
loformat.exe
|

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