0

Basically, I'm working on a batch file that would find specific files that don't include a specific character, then use a .jar file on these files. Here's the code that I have:

Set "pattern=$"

FOR /R "%PathToDirectory%" %%# in (*.class) Do (
    Echo %%~nx# | FIND /V "%pattern%" 1>NUL && (
        java -jar "somejar.jar" %%~# > test\%%~n#.java
    )
)
pause

I've checked what commands the .bat file calls out and the java call paths are valid (the .jar and the .bat are in the same directory), though the console outputs that: "The system cannot find the file specified". Same line of code that calles somejar.jar, but bruteforced (as in, the paths to the files are hard-coded in) and pretty much 1:1 to what the bat puts into the console, works just fine in another .bat file.

Safe to say, I'm confuzzled and spent more than I should have on this, so I'm asking here for a bit of help

MC ND
  • 69,615
  • 8
  • 84
  • 126
Taibi
  • 11
  • 1
  • 4
  • Windows doesn't use the # character. It ain't never going to work. – Noodles Oct 02 '14 at 14:56
  • 1
    If your paths contain spaces or special characters, the file references will not be correctly handled without quotes. Try with `java -jar "somejar.jar" "%%~#" > "test\%%~n#.java"` – MC ND Oct 02 '14 at 16:36
  • @Noodles - Even though some MS documentation claims that FOR variables should be letters, in reality, almost all byte codes are viable, including #. See http://stackoverflow.com/a/8520993/1012053 for more info. – dbenham Oct 02 '14 at 18:49

1 Answers1

0

put pushd %~dp0 at the beginning of your batch file to change the working directory to the batch file's path. i'm assuming your somejar.jar is not in c:\windows\system32, where your script will run by default if double clicked.

ths
  • 2,858
  • 1
  • 16
  • 21