Jump to content

batch dont work! "if file exist, run, else, exit"


Recommended Posts


could be that "if" parameter is bad written?

IF EXIST "%CDROM%\1.EXE" (START "" /WAIT "%CDROM%\1.EXE")
"D:\2.EXE"

Your if is bad written because you don't have good parenthesis. You need make every command go inside one set of parenthesis, but that doesn't matter, because you ignore my posts, so I am wasting my time telling you. Good luck figuring it out.

IF EXIST "D:\1.EXE" (START "" /WAIT "D:\1.EXE"
"C:\2.EXE")

Well I disagree here, the code you've quoted was mine and was given because it was believed to be correct for the task which was intended.
if exist "%CDROM%\1.exe" (Start /wait "%CDROM%\1.exe") run "C:\2.exe" ELSE (run "C:\2.exe")
exit

It appears from that example that C:\2.exe is intended to be run regardless of whether or not %CDROM%\1.exe exists, (it is found on both sides of the ELSE statement). For that reason the parentheses are closed correctly.
Link to comment
Share on other sites

At the final script is resolved as follows:

@ Echo off
for %%i in (C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) do if exist %%i\1.exe start /wait %%i\1.exe
"%~dp02.exe"

The error was SET CDROM=%%i:

Edited by maestrodellaves
Link to comment
Share on other sites

At the final script is resolved as follows: <snip />
Well without seeing the script I would be hesitant in believing that anything has been solved.

If I was however going to use the 'check every letter of the alphabet' method then I'd probably use a system to break the loop when found. (the trouble with the method you've suggested is that if the file is found at D:, the script would still check for it a E: F: G:.. etc.)

@ECHO OFF
SETLOCAL
(SET HOST_DRV=)
FOR %%# IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
CALL :SUB %%#:||GOTO :NEXT)
:NEXT
REM The commands you provided in your last message.

IF DEFINED HOST_DRV START "" /WAIT "%HOST_DRV%\1.EXE"
IF EXIST "C:\2.EXE" START "" /WAIT "C:\2.EXE"

REM The rest of your commands go here.




GOTO :EOF
:SUB
IF EXIST %1\1.EXE (SET "HOST_DRV=%1"&&EXIT/B 1)
EXIT/B 0

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...