Computing.Net > Forums > Disk Operating System > Can a batch file count directories?

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.

Can a batch file count directories?

Reply to Message Icon

Name: Matt
Date: July 22, 2001 at 21:12:25 Pacific
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: July 22, 2001 at 22:56:58 Pacific
Reply:

Hi there
I'm actually making a calculator based on batch files and you're asking me if a batch file can count??? hahahah

btw, 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


0

Response Number 2
Name: Secret_Doom
Date: July 22, 2001 at 23:02:50 Pacific
Reply:

Ooops! The post had problems...

line 4 is like this:

dateout.bat


0

Response Number 3
Name: Secret_Doom
Date: July 22, 2001 at 23:04:11 Pacific
Reply:

GRRRRRRRRRRRR
TRYING AGAIN!!!

line 4 is:

date < out2.txt |find "directory free" > out.bat


0

Response Number 4
Name: matt
Date: July 22, 2001 at 23:29:05 Pacific
Reply:

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


0

Response Number 5
Name: Matt
Date: July 22, 2001 at 23:47:10 Pacific
Reply:

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!


0

Related Posts

See More



Response Number 6
Name: Laurence
Date: July 23, 2001 at 23:45:10 Pacific
Reply:

Batfiles: The DOS batch file programming handbook


Try:

dir/ad/b |find/c/v ""

OR

dir/ad/b/s |find/c ":\"


0

Response Number 7
Name: Secret_Doom
Date: July 26, 2001 at 11:40:04 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

store processing result i... loformat.exe



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Can a batch file count directories?

Can a batch file get a files' date/time stamp? www.computing.net/answers/dos/can-a-batch-file-get-a-files-datetime-stamp/318.html

Looking for a batch file variable www.computing.net/answers/dos/looking-for-a-batch-file-variable/11008.html

How can I do this with a batch file ?........ www.computing.net/answers/dos/how-can-i-do-this-with-a-batch-file-/4850.html