Opening a file in a different folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
sp11k3t3ht3rd
Posts: 26
Joined: 20 May 2010 15:39

Re: Opening a file in a different folder

#16 Post by sp11k3t3ht3rd » 30 Jul 2010 19:53

Thanks!! Now I'm moving the java files to a folder called bin. This is my compile part of my batch file and it works.

Code: Select all

:compile
cls
if exist "Bin" (
javac *java
move *class "Bin" >NUL
pause
cls
) else (
md Bin
javac *java
move *class "Bin" >NUL
pause
cls
)
if exist "Compiled" (
move *java "Compiled" >NUL
goto start
) else (
md Compiled
move *java >NUL
goto start


The only problem is that I want it to check if there are any .java files in the original folder and if not then compile the .java files in the Compiled folder.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Opening a file in a different folder

#17 Post by aGerman » 30 Jul 2010 20:38

Maybe something like that:

Code: Select all

:compile
cls
if exist *.java (
  md Bin 2>nul
  javac *.java
  move *.class "Bin" >NUL
  pause
  cls
) else (
  md Compiled 2>nul
  pushd Compiled
  if exist *.java (
    javac *.java
    md ..\Bin 2>nul
    move *.class "..\Bin" >NUL
    pause
    cls
  )
  popd
  goto start
)


BTW To check if the folder exists is useless in your case. Use the MD command and redirect the error message to NUL (2>nul).

Regards
aGerman

Post Reply