Batch File > Javascript > Winscp > Check If File Exists
I have a batch file that will launch a .js file which, via WinSCP, checks if a file exists and returns to the batch file if it does or not. The problem IS: It always returns not fo
Solution 1:
You need to correct xpath expression in var nodes...
line.
Try something like this:
doc.setProperty("SelectionLanguage", "XPath"); //added in editvar nodes = doc.selectNodes("//w:file/w:filename[starts-with(@value, '" + filename + "')]");
and delete asterisk from FILEPATH
.
Note: first line is required in order to use XPath
as the query language, not default (and old) XSLPattern
which doesn't support methods such as starts-with
or contains
.
Solution 2:
You can use the stat
command. You can even inline the WinSCP script into the batch file:
@echo off
set REMOTE_PATH=/home/user/test.txt
winscp.com /command ^
"option batch abort" ^
"open mysession" ^
"stat %REMOTE_PATH%" ^
"exit"
if errorlevel 1 goto error
echo File %REMOTE_PATH% exists
rem Do something
exit 0
:error
echo Error or file %REMOTE_PATH% not exists
exit 1
An alternative is using the Session.FileExists
from WinSCP .NET assembly.
For further details, see the WinSCP article Checking file existence.
Post a Comment for "Batch File > Javascript > Winscp > Check If File Exists"