FOR command with multiple variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Julio Snurgoyle
Posts: 3
Joined: 22 Apr 2013 15:31

FOR command with multiple variables

#1 Post by Julio Snurgoyle » 22 Apr 2013 15:38

I searched extensively on this; I feel like this *must* have been posted somewhere and I'm just doing a bad job searching.

I'm trying to do something that I think is probably extremely basic but I lack the skill to be able to figure out how to do it on my own.

I have a command line utility that I want to run on a bunch of files.

If the command line utility had one input file and one output file (with *._in files being input and *.out being output), this is what I would use:

for %%a in (*._in) do command.exe -options "%%a" "%%~na.out"

However, this isn't the case. My utility specifies TWO input files, then outputs a combined result as ONE output file (with *.a._in and *.b._in as the two input files, and *.out as the output file).

With no knowledge of how to do it correctly, I would guess (very wrongly) that I want something like:

for %%a in (*.a._in) and for %%b in (*.b._in) do command.exe -options "%%a" "%%b" "%%~na.out"

Of course, this doesn't work.

Does anyone know how to do it correctly? (I hope this makes sense!)

I'm in a WinXP command environment, by the way.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: FOR command with multiple variables

#2 Post by foxidrive » 22 Apr 2013 16:24

You haven't told us much detail - what exe is this so we can look at the help?

FWIW there are methods to parse the names but knowing the filename makeup helps to decide which method to use.

EG: are the any filenames like name.part2.a._in with periods in the rootname?

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: FOR command with multiple variables

#3 Post by Aacini » 22 Apr 2013 16:40

The Batch code below assume that for each file named *.a._in it must exist a file named *.b._in:

Code: Select all

for %%a in (*.a._in) do (
   for %%b in ("%%~Na") do command.exe -options "%%a" "%%~Nb.b._in" "%%~Na.out"
)


You may also do a merge of two lists with different named files.

Antonio

Julio Snurgoyle
Posts: 3
Joined: 22 Apr 2013 15:31

Re: FOR command with multiple variables

#4 Post by Julio Snurgoyle » 23 Apr 2013 15:04

Thanks very much Aacini for that, that's exactly what I needed!

The only thing though, is that all the files have the same extension (they're .wav files actually :)), so the in files are *.a.wav and *.b.wav, and the out files should be just *.wav. However, the outfiles end up being named *.a.wav, so they overwrite the original wav files. I could do "subdir\%%~na.wav", but the files will still need renamed to take the .a out.

You can't think of any way to do it in the batch file, can you? I guess that would actually involve editing one of the variables (stripping the .a out).

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: FOR command with multiple variables

#5 Post by foxidrive » 23 Apr 2013 22:31

Use this as the out filename: "%%~Nb.wav"

Julio Snurgoyle
Posts: 3
Joined: 22 Apr 2013 15:31

Re: FOR command with multiple variables

#6 Post by Julio Snurgoyle » 08 May 2013 22:05

foxidrive wrote:Use this as the out filename: "%%~Nb.wav"


I apologize for taking so long to reply. Life got in the way! :?

THANKS for the help! "Of course! I should have known!" :mrgreen:

Post Reply