• Please review our updated Terms and Rules here

Recursing directories in plain old DOS (not NT)

RichCini

Veteran Member
Joined
Aug 7, 2005
Messages
547
Location
Long Island, NY
All --

I'm working on a Windows 3.1-related project which has a folder with say 20 subdirectories, each with the code (and makefile) for a driver. The compiler package is in the path, so my idea was to use a "for" loop to traverse into each folder, run NMAKE, then go to the next folder.

I've done some searching and it seems this is easily done...in Windows NT...not DOS. I also thought about creating a file containing the directory names (one name per line), but I can't figure out how to make that work, either.

Batch file programming wasn't my strength back then, and apparently still isn't. Maybe there's a program out there that does this. If so, I'd appreciate knowing the name.

Thanks!

Rich
 
Here is a tool I keep in my DOS tool box called RECURSE (13KB)

www.kc8eyt.com/downloads/RECURSE.EXE

It will run a DOS command in the current directory and all sub directories in the tree from that point

Example:

RECURSE DEL *.BAK

The above command will delete all files with the extension BAK in the current directory and all sub directories.

This little tool may help you achieve your goal.
 
Here is a tool I keep in my DOS tool box called RECURSE (13KB)

www.kc8eyt.com/downloads/RECURSE.EXE

It will run a DOS command in the current directory and all sub directories in the tree from that point

Example:

RECURSE DEL *.BAK

The above command will delete all files with the extension BAK in the current directory and all sub directories.

This little tool may help you achieve your goal.

Outstanding! Thanks.

Next thing I'm looking for -- and maybe you have this too -- is a tool that will perform that recursion from a list. So, a file would contain a list of directories and it would only recurse into those directories. It would just be a way to avoid recursing into non-code folders, like "docs" and "include", for example.

Thanks again!
Rich
 
Outstanding! Thanks.

Next thing I'm looking for -- and maybe you have this too -- is a tool that will perform that recursion from a list. So, a file would contain a list of directories and it would only recurse into those directories. It would just be a way to avoid recursing into non-code folders, like "docs" and "include", for example.

Thanks again!
Rich

You could write a simple QuickBasic 4.5 program to do that and then SHELL your desired command to each sub directory. Something like this:

OPEN "LIST.TXT" FOR INPUT AS #1
DO
LINE INPUT Subdir$
Subdir$ = "."+Subdir$+""
SHELL Subdir$ + "<your command here>"
LOOP UNTIL EOF(!)
CLOSE #1
 
Last edited:
On line 4 there should be a backslash inside the quotes after the . and again a lone backslash inside the second set of quotes.

They keep getting stripped when I save?

Code:
OPEN "LIST.TXT" FOR INPUT AS #1
DO
    LINE INPUT #1, Subdir$
    Subdir$ = ".\" + Subdir$ + "\"
    SHELL Subdir$ + "<your command here>"
LOOP UNTIL EOF(1)
CLOSE #1

Let's see if code tags help.
 
Last edited:
There's also a sort-of command-line C program in SIMTEL20 called CENVI or CENWIN. Very clever stuff.
Somewhere in SIMTEL20 is my contribution called IRP.

To delete every .BAK file in a tree, you'd do something like this:

DIR /S /B *.BAK } IRP DEL @1

Lots of ways to skin this cat.
 
If you know sed(1) from Unix, you can get a DOS version of SED and use it to transform a list of directories into a batch file (the one I have is 22K). Once upon a time I wrote a DOS software deployment tool that was basically batch files using sed to modify files. In NT you can just pipe the output from sed into cmd.exe, but in DOS you needed to put the output in a .bat file first, then "call" it. I know it works in DOS 5.x and 6.x but I don't recall if I've ever tested it in earlier versions.

If you don't already know sed this may not be a convenient time to learn it.
 
This is good stuff. I have the SIMTEL20 CD here so I can look for CEN*. I like the idea of BASIC since that's part of DOS (I'm running 6.22 in the VM) and it gives me an excuse to try it. Will report back once I give it a try.

I'm trying to replicate a build tool used in the NT DDK which, among other things, traverses a folder tree and runs the build on each folder. All you have to do is put a new source folder in the tree and add the name to the text file with the directories in it. I did try RECURSE, and a PC/Magazine analog called SWEEP and they work fine, but of course barf in folders that have no buildable targets. Feels like the BASIC program or maybe CENVI will do it.
 
It might be using the backslash as an escape character.

Let's see...

OPEN "LIST.TXT" FOR INPUT AS #1
DO
LINE INPUT Subdir$
Subdir$ = ".\"+Subdir$+"\"
SHELL Subdir$ + "<your command here>"
LOOP UNTIL EOF(!)
CLOSE #1

Yes, it is.
 
It might be using the backslash as an escape character.

Let's see...

OPEN "LIST.TXT" FOR INPUT AS #1
DO
LINE INPUT Subdir$
Subdir$ = "."+Subdir$+""
SHELL Subdir$ + "<your command here>"
LOOP UNTIL EOF(!)
CLOSE #1

Yes, it is.

Yeah, I was a dummy for not using CODE tags in the first place. The second listing in the code box is correct.
 
Ok, I gave the corrected code a try and it doesn't work as-is, but I believe it's because of how NMAKER works and how the MAKEFILES are constructed. If you edit it as follows, it works just fine. I think the makefiles rely on the working directory changing. Thanks for the help with this!


Code:
OPEN "LIST.TXT" FOR INPUT AS #1 DO LINE INPUT #1, Subdir$
CHDIR Subdir$
SHELL "nmaker"
CHDIR ".."
LOOP UNTIL EOF(1)
CLOSE #1

Rich
 
Ok, I gave the corrected code a try and it doesn't work as-is, but I believe it's because of how NMAKER works and how the MAKEFILES are constructed. If you edit it as follows, it works just fine. I think the makefiles rely on the working directory changing. Thanks for the help with this!


Code:
OPEN "LIST.TXT" FOR INPUT AS #1 DO LINE INPUT #1, Subdir$
CHDIR Subdir$
SHELL "nmaker"
CHDIR ".."
LOOP UNTIL EOF(1)
CLOSE #1

Rich

Cool, glad you were able to make it work. The code I posted was pretty general, glad you were able to modify it to your needs.
 
To top this off, I'll submit a gem I penned in 1985. Essentially takes a list of files from stdin, (even more than one file per line), parses them and executes a program on them.

Code:
; Honors -
; !@ - the whole line
; !a - a parameter
; !:a - the diskette drive name, with the :,
;        null if none specified
; !\a - the path name up to, but not including the file
;         name, and excluding the drive name. Includes
;         terminal '\'.
; !*a - the file name, not including the extension
; !.a - the extension, if any. Includes a leading "."
;
; Note also, if the command starts with "@", the command isn't echoed
; to stdout before execution.

About 1K executable.

MODS: PLEASE fix inclusion of pasted source to not elide multiple spaces.
 

Attachments

  • irprun.zip
    5.9 KB · Views: 1
Back
Top