2012-10-26 55 views
2

.bat文件我試圖創建兩個蝙蝠文件。一個是C.BAT,另一個是r.bat編譯和運行Java的東西

C.BAT只包含:

cls 
javac *.java 

這將編譯所有的.java文件。

在r.bat我:

cls 
java * 

它不會運行的類文件。我認爲它是因爲在「的Java *」行*轉換爲「Java的Class1.class」,「Java的Class2.class」等時,其中一個應該是「Java的1類」和「Java類2」而已。 (沒有擴展名)我該怎麼做?我剛開始學習這些東西,我無法在任何地方找到正確的答案。

回答

2

了在C:\java\stuff發現所有的.java文件下面的循環和運行它們一個接一個。該%%~nf被格式化的文件名不顯示文件擴展名即Java類名。如果更改java %%~nfecho 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. 
+1

的感謝!雖然我不知道這是如何做到的,但它起作用。我會爲自己找出它是如何做到的,再次感謝你@sudo_o – kentz