2

2つのbatファイルを作成しようとしています。1つはc.batで、もう1つはr.batです。

c.batには次のものが含まれています。

cls
javac *.java

これにより、すべての.javaファイルがコンパイルされます。

r.batで私は持っています:

cls
java *

クラスファイルは実行されません。これは、「java*」行の*が「javaClass1.class」、「java Class2.class」に変換されるためだと思います。したがって、「javaClass1」と「javaClass2」のみの場合に1つになります。(拡張機能なしで)どうすればこれを行うことができますか?私はこれらのことを学び始めたばかりで、どこにも正しい答えを見つけることができません。

4

1 に答える 1

2

.java以下は、で見つかったすべてのファイルをループし、C:\java\stuffそれらを次々に実行します。は、ファイル拡張子、つまりJavaクラス名%%~nfを表示しないようにファイル名をフォーマットしています。に変更すると、何が起こっているかを正確に確認できます。 java %%~nfecho java %%~nf

cls
for "C:\java\stuff" %%f in (*.java) do (
    java %%~nf
)

対象:次のオプションを使用できます

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. 
于 2012-10-26T16:19:45.033 に答える