0

i am trying to write a simple winscp script to use it inside a for loop, in a batch file. The loop is :

for /F "tokens=2 delims==" %%s in ('set REMOTE_PATH[') do ("    
ECHO CHECKING FOR %%s
winscp.exe /console /script=run01test1 /parameter // %%s
IF  %ERRORLEVEL% neq 0 (
    ECHO FILE %%s DOES NOT EXIST
    CALL:error10 "76" "UNABLE TO LOCATE TARGET FILE %%s "
    CALL:ERRORNOTIFYMAIL "UNABLE TO LOCATE TARGET FILE %%s" "FATAL" "CHECK EXISTENCE OF TARGET DIRECTORY" "77"
    EXIT /B 10
) ELSE (
ECHO FILE %%s EXISTS
)
ECHO.   
)

and the run01test1 winscp script is :

open sftp://xxx:[email protected]
stat "%1%"
exit

My problem is, that it either doesnt pass the parameter right, or for some reason the return value always returns zero whether the command stat succeeds or not. For the record, the idea is to check if files exist, the files are stored in an array in the style of :

set remote_path[0]
set remote_path[1]...

Can anyone help? Thanks in advance

1

1 Answer 1

2

You've got an delayed expansion problem with your %errorlevel% variable.

Either enable delayed expansion with setlocal enabledelayedexpansion and use !errorlevel! inside your code block, or use an alternative syntax:

if errorlevel 1 (...

which checks if errorlevel is 1 or higher. (see if /? for description)

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

Comments

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.