对目录中的每个文件运行批处理命令


10

我有一个使用以下语法的Java程序:

command.jar namefile

我必须在目录中为1600个文件运行此程序。如何自动为每个文件运行此命令?

是否有DOS批处理命令?还是另一种方式?

Answers:


14

到目前为止,最简单的方法是简单地对所有文件运行for循环。好处是set(for-loop 的输入)确实接受与normal相同的通配符cmd。

用于批处理文件:

FOR %%f IN (*) DO command.jar %%f

从命令行使用:

FOR %f IN (*) DO command.jar %f

Hi! It works with this: for %f in (*) do command.jar %f Really really thanks! :)

@E_M: Edited my answer to make that clear.
— Bobby

This is because you have to escape the % in a batch file. To be safe you should first append 'echo' to the beginning of the command to see what exactly will be executed.
— mrexodia
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.