批量处理目录下的所有文件
现在我编写了一个批处理作业,它调用另一个文件并传入可执行文件需要运行的变量(密码和文件名)。
例如:
> cd f:\test\utils
> admin import-xml -Dimport.file=f:\DB\file1.xml -Dadmin.db.password=test123
我写了一个执行此操作的作业,但发现会有多个文件。
用户名和密码永远不会改变,但大约 15 个不同的 xml 文件的文件名有所不同——也许很快还会有更多文件。
这些文件将始终位于同一文件夹中。我可以编写一些东西来处理此目录中的每个文件,而不是以 15-20 个作业(每个文件一个)结束。或者等到一个文件完成后再下一个文件,或者我可以在开始下一个文件之前添加 3 分钟的睡眠时间。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
%%~dpnxF
扩展为 drive、path、basename 和 e x当前文件的张力。如果您打算在该循环中设置并使用环境变量 (
%foo%
),请在遇到麻烦之前先阅读help set
。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, readhelp set
first before you get into trouble.您可以使用
for
命令。批处理文件中类似这样的内容:假设您正在运行的
admin
命令在作业完成之前不会返回,上面的循环将按顺序处理它们。如果您在提示符下运行命令(而不是在批处理文件中),则仅使用单个 %。
You can use the
for
command. Something like this in a batch file:Assuming that the
admin
command you are running doesn't return until the job is finished, the above loop would process them sequentially.If you run the command at the prompt (as opposed to in a batch file), only use a single %.