我正在尝试创建两个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”。 (没有扩展)我该怎么做?我刚刚开始学习这些东西,但在任何地方都找不到正确的答案。
最佳答案
以下循环遍历在 C:\java\stuff
中找到的所有 .java
文件,并依次运行它们。 %%~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.
关于java - 用于编译和运行java东西的.bat文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13090609/