0

I have a batch script that is calling a VBscript file. It reiterates through all files in a watched folder.

It needs to verify if the file name has spaces in it and if so reject the file and not process it with the VBS.

I must have an error on the code as I get the error message:

ELSE was not expected at this time.

I have looked at the documentation and searched for the answer for quite some time, including this question: check "IF" condition inside FOR loop (batch/cmd)

But still, I can't see what is wrong in my syntax:

@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
call :ReadIni Infolder inFolder 
call :ReadIni Outfolder outFolder 

echo %inFolder%
echo %outFolder%

pause

:StartLoop
FOR %%I in (%inFolder%\*.srt) DO (
  ECHO %%I
  ECHO %%~nxI
  SET TESTNAME=%%~nxI
  ECHO !TESTNAME!
  ECHO !TESTNAME: =_!
  PAUSE
  IF NOT !TESTNAME!==!TESTNAME: =_! (
    move "%~sdp0%%~nxI" "%outFolder%\ERROR_IN_FILE_NAME_%%~nxI"
  ) ELSE (
    copy /y "%%I" "%~sdp0%%~nxI"
    %~sdp0SRToffset.vbs "%~sdp0%%~nxI" "%~sdp0%%~nxI"
    IF %ERRORLEVEL%==1 (
      Goto StartLoop
    ) else (
      move "%~sdp0%%~nxI" "%outFolder%\"
      move "%~sdp0QC_%%~nxI" "%outFolder%\"
      del "%%I"
    )
  )
)
timeout /t 1
goto StartLoop

:ReadIni
FOR /F "tokens=2 delims==" %%a in ('find "%~1=" config.ini') do set %~2=%%a
exit /b

Any help would be appreciated.

1 Answer 1

2
IF NOT "!TESTNAME!"=="!TESTNAME: =_!" (

 ...

IF %ERRORLEVEL%==1 (

Quoting the strings causes cmd to regard the string as a single entity.

Note that the following if %errorlevel% will be executed using the value of errorlevel at :startloop. (See delayed expansion for reasoning.)

Cure by using if !errorlevel!==1 (. (Using the runtime value of errorlevel as established by the vbs routine.)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I just figured it out, too. This is what I ended up using IF "!TESTNAME!" NEQ "!TESTNAME: =_!" ( and thanks for pointing out the error in errorlevel. I changed it to IF ERRORLEVEL 1 (

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.