Passing multiple files into batch file

May 18, 2009 at 12:42:12
Specs: Windows Vista
I am passing set of files (%1, %2...%n) into a batch file to perform a particular command on each file. The problem is that the number of files can vary. Sometimes I pass 1 file, sometimes I pass 1000 files. Normally you would do something like:

command.exe %1 %2 %3 %4

but how would I do this for varied number of files? Can I loop through and perform the command for each file regardless of how many are passed in? How can I assign a variable %x and increment x until all the files are inputted?

See More: Passing multiple files into batch file

Report •

May 18, 2009 at 13:53:12
I don't see how you could pass 1000 command line parameters.

If you put filenames in a txt file you can use a FOR loop.

If at first you don't succeed, you're about average.


Report •

May 18, 2009 at 15:27:53
True. I'm sure there is a limit, but even so, isn't there a way to loop through the file parameter variables and execute the command for each file parameter within the batch file?

Report •

May 18, 2009 at 15:30:45
I'm not sure what the limit is but I'm pretty certain it is well above 9......

do stuff with %1
shift /1
::makes %2 become %1, %3 become %2......%0 is unaffected
if not "%~1"=="" goto loop


for %%a in (%*) do (
stuff with %%a

Report •

Related Solutions

May 18, 2009 at 17:04:46
This shift command is doing the trick. Thanks!

Report •

Ask Question