I have a set of base filenames, for each name 'f' there are exactly two files, 'f.in' and 'f.out'. I want to write a batch file (in Windows XP) which goes through all the filenames, for each one it should:
- Display the base name 'f'
- Perform an action on 'f.in'
- Perform another action on 'f.out'
I don't have any way to list the set of base filenames, other than to search for *.in (or *.out) for example.
Expanding on Nathans post. The following will do the job lot in one batch file.
Assuming you have two programs that process the two files, process_in.exe and process_out.exe:
%%~nf is a substitution modifier, that expands %f to a file name only. See other modifiers in https://technet.microsoft.com/en-us/library/bb490909.aspx (midway down the page) or just in the next answer.
Echoing f.in and f.out will seperate the concept of what to loop and what not to loop when used in a for /f loop.
Although you didn't ask, a good way to pass commands into f.in and f.out would be to...
A link to all the Windows XP commands:link
I apologize if I did not answer this correctly. The question was very hard for me to read.
Easiest way, as I see it, is to use a for loop that calls a second batch file for processing, passing that second file the base name.
According to the for /? help, basename can be extracted using the nifty ~n option. So, the base script would read:
Then, in process.cmd, assume that %0 contains the base name and act accordingly. For example:
There might be a better way to do this in one script, but I've always been a bit hazy on how to pull of multiple commands in a single for loop in a batch file.
EDIT: That's fantastic! I had somehow missed the page in the docs that showed that you could do multi-line blocks in a FOR loop. I am going to go have to go back and rewrite some batch files now...
There is a tool usually used in MS Servers (as far as I can remember) called forfiles:
The link above contains help as well as a link to the microsoft download page.
The code below filters filenames starting with given substring. It could be changed to fit different needs by working on subfname substring extraction and IF statement: