windows 将文件添加到类路径或批处理文件中的循环?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4441880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:48:02  来源:igfitidea点击:

Add files to classpath or loops in batch files?

windowsscriptingbatch-file

提问by Daniil

I have this script in BASH (linux) shells script that adds all *.jar files into the classpath automatically. Is there a way to do the in window's batch file or do I have to add all the files manually?

我在 BASH (linux) shells 脚本中有这个脚本,它自动将所有 *.jar 文件添加到类路径中。有没有办法在窗口中执行批处理文件,还是必须手动添加所有文件?

CLASSPATH=.
for file in ./libs/*.jar; do
    CLASSPATH=$CLASSPATH:$file
done 

Thanks!

谢谢!

回答by Sanjit Saluja

Use the forfilescommand to loop over the file names.

使用forfiles命令循环遍历文件名。

forfiles /M .\libs\*.jar /C "cmd /c set CLASSPATH=%CLASSPATH%;@file"