批量处理目录中的所有文件 [英] Batch process all files in directory
问题描述
现在我有一个批处理作业我写了调用另一个文件传递的变量可执行需要运行(密码和文件名)。
例如:
> CD F:\\测试\\ utils的
>管理员进口XML -Dimport.file = F:\\ DB \\ file1.xml -Dadmin.db.password = test123
我写了一份工作,这样做,但发现会有多个文件。
用户名和密码永远不会改变,但文件名不同,像15个不同的XML文件 - 有可能更多即将推出
。该文件将始终位于同一个文件夹中。相反,像15-20作业(每个文件)结束了,我可以写的东西,将处理位于此目录中的每个文件。 ,要么等到一个是前一个已完成或启动下一个文件之前,我可以添加一个3分钟的睡眠。
pushd将C:\\测试\\ utils的
为%% f由于(F:\\ DB \\ * XML)做(
管理员进口XML-Dimport.file = %%〜dpnxF-Dadmin.db.password = test123
)
POPD
的 %%〜dpnxF
扩展到 D 里沃, P ATH,基地的 ñ火焰和电子邮件的 X 当前文件的紧张局势。
如果您打算设置的和的在循环使用环境变量(%富%
),读帮助集
你遇到麻烦之前,先
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:\test\utils
> admin import-xml -Dimport.file=f:\DB\file1.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.
pushd C:\test\utils
for %%F in (F:\DB\*.xml) do (
admin import-xml "-Dimport.file=%%~dpnxF" -Dadmin.db.password=test123
)
popd
The %%~dpnxF
expands to drive, path, basename and extension 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.
这篇关于批量处理目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!