Click here for important information about

batch file with 3 inputs

February 17, 2010 at 13:39:27
Specs: Windows 7

I'm not too sure if this is the right place for this (i thought DOS but then saw a post that indicated otherwise) but i hope someone who has experience with this might be able to shed some light.

I'm trying to write a batch file but not getting very far at all. I've written a program that i want to send arguments to.

The idea of the batch file is to loop through all the files in one directory and all the files in a second directory, and then send them both to my app as arguments. So, dir1 and dir2 have say 50 files in them, it should send myapp - file1FromDir1 file1FromDir2 on the first iteration, myapp - file2FromDir1 file2FromDir2 on the second iteration, etc. It would also be nice to be able to do some checks for extensions and corresponding numbers of files etc, but i don't mind that so much.

Problems with it sending the wrong files shouldn't be too much of an issue as they're all ordered 00, 01, 02, in each directory to correspond to each other.

Any ideas? I've been messing around with this for ages, not having written many complicated batch files before and it's honestly just gotten to the point where im wasting time trying to figure this out when i could actually be writing code for my app.

Thanks in advance

See More: batch file with 3 inputs

February 17, 2010 at 17:41:53
Does it matter how the files are paired up between the two directories? For example do they need to be sent with a file of the same name in the other directory, or is it completely at random and you just stop when there are no more files in the smaller of the two directories?

Report •

February 17, 2010 at 18:25:57
Hi, thanks for the reply

It does matter, the first directory would have files like this:

The second directory would be something like this:

abc_000.jpg and xyz_000.bmp correspond to each other and are what need to be sent (along with their path) to the app. Each pair of files would be sent in this manner until there are no more pairs.

It should be noted that it doesn't really matter if they don't process the pairs in order, just that the two files that make up a pair need to match.


Report •

February 17, 2010 at 19:46:11
see if this works:

pushd c:\jpgfiles
for /f "tokens=1-3 delims=_." %%a in ('dir /b ???_*.jpg') do (
set zz=%%a
set nn=%%b
for /f %%m in ('dir c:\bmpfiles\???_%%b.bmp') do (
echo %%a_%%b.jpg %%m
call myapp %%a_%%b.jpg %%m

warning: many assumptions were ventured!
3-char. lead-in token (abc, xyz, etc, hence: ???)
_ as separator always consistant
numbers always same format in both dir.s (001 or 01 or 0001)

Report •

Related Solutions

February 18, 2010 at 03:33:31
To use the script below you will need to tailor the paths in the first 2 FOR loops.

Also, this does not check to see if there are an equal number of files in the 2 directories.

Finally, when it looks like it's acting OK remove the ECHO in front of myapp.

@echo off & setLocal EnableDELAYedeXpansion

set N=
for /f "tokens=* delims= " %%a in ('dir/b/on/a-d \files\*.bak') do (
set /a N+=1
set O!N!=%%a

set N=
for /f "tokens=* delims= " %%a in ('dir/b/on/a-d *.bak') do (
set /a N+=1
set T!N!=%%a

for /L %%i in (1 1 !N!) do (
echo myapp - dir1\!O%%i! dir2\!T%%i!

Helping others achieve escape felicity


Report •

February 18, 2010 at 09:59:36
Thanks very much :) Works perfectly.


Report •

Ask Question