Reputation: 39
I wrote a batch file that compiles all .java files using javac:
javac *.java
But then I added another file, which I do not want to compile. For example let's name it ignored.java
Is there a way in batch programming to exclude something from code execution?
Something like:
javac *.java /except ignored.java
Upvotes: 1
Views: 317
Reputation:
cmd
requires a for
loop to do something for
each item. if
can be used to compare. That will give you a solution of:
@echo off
for %%i in (*.java) do if /i not "%%~i" == "ignored.java" javac "%%~i"
Note also the /i
switch for if
which makes the comparison case insensitive.
Upvotes: 2
Reputation: 1606
Another way is to use Argument File
Create a file named classes
that contains only files to be compiled like following:
MyClass1.java
MyClass2.java
MyClass3.java
You can do that like this:
dir *.java /a:-d /b|find /i /v "ignored.java">classes
Then, run the javac command as follows:
javac @classes
As ignored.java is not mentioned in classes file, it will be skipped
Upvotes: 2