VOGONS


First post, by Kahenraz

User metadata
Rank l33t
Rank
l33t

In NT I can use this to loop over a directory to get all files and folders into %f:

FOR /D %f IN (".\*") DO ECHO %f

However, DOS 7.1 does not have the /D switch and will only return files. Do I have to write "DIR /B" to a file and then read that back into FOR or is there an easier way?

Reply 1 of 9, by jwt27

User metadata
Rank Oldbie
Rank
Oldbie

4DOS can do this.

edit:
The 4DOS variant of that line is:

FOR /A: %f IN (*.*) DO ECHO %f

where /A: specifies the file attributes. No attributes means all files, including directories.

Reply 2 of 9, by Samir

User metadata
Rank Member
Rank
Member
Kahenraz wrote:

However, DOS 7.1 does not have the /D switch and will only return files.

Wow, that's stupid. Way to go Microsoft! 😠

Reply 3 of 9, by Kahenraz

User metadata
Rank l33t
Rank
l33t

I know, really. Ye olden DOS batch commands are virtually useless for anything remotely constructive. I've been pining for good old Unix Bash on DOS. Sad, I know! But with DJGPP I can have my cake and eat it too. 😈

Reply 4 of 9, by Samir

User metadata
Rank Member
Rank
Member

You need to check out the forum at http://www.dostips.com. These guys are AMAZING with DOS batch files. They've even written full-out games using nothing but batch. 😳

Reply 5 of 9, by Kahenraz

User metadata
Rank l33t
Rank
l33t

The problem is that most of those examples most likely use the new NT variants of commands.

I used to do a lot with regular bat files until I came to the realization how broken they really are. For each line in a bat file, when it is evaluated, the ENTIRE file is reevaluated. This. THIS!

Once you reach a certain file length, each additional line slows down the entire script SIGNIFICANTLY.

Reply 6 of 9, by jwt27

User metadata
Rank Oldbie
Rank
Oldbie

Just try 4DOS! You won't regret it... I honestly prefer 4DOS + GNU coreutils over bash.

Reply 7 of 9, by Kahenraz

User metadata
Rank l33t
Rank
l33t

Do you have a link to GNU coreutils for DOS? Or are you referring to DJGPP's core utils?

Reply 9 of 9, by Samir

User metadata
Rank Member
Rank
Member
Kahenraz wrote:

The problem is that most of those examples most likely use the new NT variants of commands.

I used to do a lot with regular bat files until I came to the realization how broken they really are. For each line in a bat file, when it is evaluated, the ENTIRE file is reevaluated. This. THIS!

Once you reach a certain file length, each additional line slows down the entire script SIGNIFICANTLY.

I usually try to make my batch files pure MSDOS batch, and a lot of people can do that if need be for a particular project.

That's true that they do get evaluated pretty inefficiently once they get too large. But for a lot of things, they're still faster in the end.