Saturday 15 January 2011

windows - Run program in subfolders -



windows - Run program in subfolders -

i'm trying write windows batch script run 2 programs through bunch of folders. i'm not expert @ shell scripting seek best.

here's i'm trying run through each folder...

the input program1 .extension1 file produces .extension2 file run through program2 generate need.

before run script cd folder. programs copied folder because work in current working directory.

copy c:\program1 . re-create c:\program2 . %i in (*.extension1) program1 "%i" %i in (*.extension2) program2 "%i"

the info folder shown above contains hundreds of folders need run programme in. i'd able in 1 big batch script.

class="lang-dos prettyprint-override">@echo off setlocal set "sourcedir=u:\sourcedir\one" pushd "%sourcedir%" /r %%a in (*.ext1) ( pushd "%%~dpa" echo(c:\program1 "%%~nxa" popd ) popd goto :eof

you need alter setting of sourcedir suit circumstances.

in probability, need - or @ least, framework.

note routine echo required commands. allows harmless test (on representative sub-tree) ensure process should work on entire tree.

changing echo(c:\program1 c:\program1 should execute first programme on each .ext1 file in sub-tree. unusual programme check file exists within same directory executable - if won't take path, "the current directory" assumed.

you don't whether programme program1 produces file called whatever.ext2 whatever.ext1 or whether produces somethingradicallydifferent.ext2. in probability, same name used.

if case, run sec program, add together after

echo(c:\program1 "%%~nxa"

echo(c:\program2 "%%~na.ext2"

otherwise, repeat entire block, changing ext1 ext2

(i'll assume can figure out i've abbreviated extensions)

if, on off-chance program(s) need in same directory, replace

echo(c:\program1 "%%~nxa"

with

echo n|c:\program1 . >nul 2>nul echo(program1 "%%~nxa"

(and ditto programme 2, obviously). here n echoed copy, copy take place once. improved theoretical requirement anyway since it's 99.9999% executing c:\program? work quite happily.

windows batch-file cmd

No comments:

Post a Comment