我正在尝试创建两个bat文件。一个是c.bat,另一个是r.bat
c.bat只包含:
cls
javac *.java
将编译所有.java文件。
在r.bat中我有:cls
java *
它不会运行类文件。我认为这是因为“java *”行中的*转换为“java Class1.class”,“java Class2.class”,因此只应该是“java Class1”和“java Class2”。 (没有扩展名单)我该怎么做?我刚开始学习这些东西,我无法在任何地方找到正确的答案。
答案 0 :(得分:2)
以下循环遍历.java
中找到的所有C:\java\stuff
文件并一个接一个地运行它们。 %%~nf
格式化文件名以不显示文件扩展名,即java类名。如果您将java %%~nf
更改为echo java %%~nf
,则可以准确了解正在发生的事情。
cls
for "C:\java\stuff" %%f in (*.java) do (
java %%~nf
)
For:可以使用以下选项:
Variable with modifier Description
%~I Expands %I which removes any surrounding
quotation marks ("").
%~fI Expands %I to a fully qualified path name.
%~dI Expands %I to a drive letter only.
%~pI Expands %I to a path only.
%~nI Expands %I to a file name only.
%~xI Expands %I to a file extension only.
%~sI Expands path to contain short names only.
%~aI Expands %I to the file attributes of file.
%~tI Expands %I to the date and time of file.
%~zI Expands %I to the size of file.
%~$PATH:I Searches the directories listed in the PATH environment
variable and expands %I to the fully qualified name of
the first one found. If the environment variable name is
not defined or the file is not found by the search,
this modifier expands to the empty string.