Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
875 views
in Technique[技术] by (71.8m points)

windows - Batch process all files in directory

Right now i have a batch job I wrote that calls another file and passes in the variables that executable needs to run (password and filename).

Ex:

> cd f:estutils 
> admin import-xml -Dimport.file=f:DBfile1.xml  -Dadmin.db.password=test123

I wrote a job that does this, but found out that there would be multiple files.

The username and password never change but the filename differs for like 15 different xml files--with maybe more coming soon.

The files will always be located in the same folder. Instead of ending up with like 15-20 jobs (one for each file), can I write something that will process each file located in this directory. And either wait till one is completed before the next or I can add a 3 min sleep before it starts the next file.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
pushd C:estutils
for %%F in (F:DB*.xml) do (
   admin import-xml "-Dimport.file=%%~dpnxF" -Dadmin.db.password=test123
)
popd

The %%~dpnxF expands to d?rive, p?ath, base?n?ame and e?x?tension of the current file.

If you intend to set and use environment variables (%foo%) in that loop, read help set first before you get into trouble.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...