Reputation: 3
I have the following batch file. Basically it scans a director which has files in pairs with the same name but different extension *.TXT and .AVI. If the Text file name corresponding to the AVI file name exists, the AVI file is not played. Otherwise it should be played by the specified application. It seems environment variables are the issue between the the loop and the if. I have read almost all related posts on Batch files which to do with environment variables. None of them worked. I also tried with and without EnableDelayedExpansion, but no luck. Also tried == instead of EQU but no luck. All Echo statements are for Debugging. Here is my attempt.
@echo off
SetLocal EnableDelayedExpansion
SET MyApp="C:\Program Files\VideoLAN\VLC\vlc.exe"
ECHO MyApp is %MyApp%
SET PathToDB=C:\1
ECHO PathToDB is %PathToDB%
FOR %%X in (%PathToDB%\*.avi) DO (
ECHO Q. %%X
SET ABC=YES
IF EXIST "%PathToDB%\%%~nX.txt" (
ECHO Coressponding Text File Exists ....[%%~nX.txt]....
SET ABC=[NO]
)
ECHO 1 %ABC%
ECHO 1 !ABC!
if !ABC! EQU "YES" %MyApp% %%X
if !ABC! EQU "YES" !MyApp! %%X
)
Thanks for any helpful suggestions
Upvotes: 0
Views: 64
Reputation: 2231
You should use EQU
only for numerical comparisons. Because you are comparing text you should use ==
but remember: the whole text (each character) at the left must be identical to the whole text to the right of the ==
operator. The condition in the IF-statement if !ABC! == "YES" %MyApp% %%X
will never evaluate to true since the right part contains double quotes "
and the left part doesn't. So it should be:
if "!ABC!" == "YES" %MyApp% %%X
Upvotes: 2