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:xxx@xx.xx.xx.xx
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

aschipfl
  • 33,626
  • 12
  • 54
  • 99
onlyf
  • 767
  • 3
  • 19
  • 39
  • 1
    without testing - may it be a [delayed expansion problem](http://stackoverflow.com/a/30284028/2152082) with `%errorlevel%`? – Stephan Jan 26 '17 at 07:34

1 Answers1

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)

Community
  • 1
  • 1
Stephan
  • 53,940
  • 10
  • 58
  • 91