Differences
This shows you the differences between the selected revisions of the page.
script_checking_file_existence 2018-08-20 | script_checking_file_existence 2024-09-02 (current) | ||
Line 3: | Line 3: | ||
===== [[remote]] Remote file existence ===== | ===== [[remote]] Remote file existence ===== | ||
- | ==== [[net]] Using WinSCP .NET Assembly ==== | + | ==== [[library]] Using WinSCP .NET Assembly ==== |
Use method ''[[library_session_fileexists|Session.FileExists]]'' from [[library|WinSCP .NET assembly]]. | Use method ''[[library_session_fileexists|Session.FileExists]]'' from [[library|WinSCP .NET assembly]]. | ||
Line 19: | Line 19: | ||
See complete [[library_session_fileexists#powershell|PowerShell example for Session.FileExists]]. | See complete [[library_session_fileexists#powershell|PowerShell example for Session.FileExists]]. | ||
- | If you are not looking for a specific file, but for any file matching a mask (e.g. ''*.txt''), you can use the ''[[library_session_enumerateremotefiles|Session.EnumerateRemoteFiles]]''. For a complex example, that uses this technique, see [[script_downloading_when_done_file_exists#separate|Downloading files from FTP/SFTP server only after "done" file is created]]. | + | If you are not looking for a specific file, but for any file matching a mask (e.g. ''*.txt''), you can use the ''[[library_session_enumerateremotefiles|Session.EnumerateRemoteFiles]]''. For a complex example, that uses this technique, see [[script_downloading_when_done_file_exists#separate|*]]. |
~~AD~~ | ~~AD~~ | ||
Line 42: | Line 42: | ||
:error | :error | ||
- | echo Error or file %REMOTE_PATH% not exists | + | echo Error or file %REMOTE_PATH% <nohilite>not</nohilite> exists |
exit /b 1 | exit /b 1 | ||
</code> | </code> | ||
- | If the further processing involves WinSCP commands, you can add the commands directly to the main WinSCP script, just after the ''stat'' command. For an example, see [[script_downloading_when_done_file_exists#fixed_scripting|Downloading files from FTP/SFTP server only after "done" file is created]]. | + | If the further processing involves WinSCP commands, you can add the commands directly to the main WinSCP script, just after the ''stat'' command. For an example, see [[script_downloading_when_done_file_exists#fixed_scripting|*]]. |
To check for existence of any file matching a mask, instead of a specific file, enable ''[[scriptcommand_option#failonnomatch|option failonnomatch on]]'' mode and use ''[[scriptcommand_ls|ls mask]]'' command, instead of ''stat name'' command: | To check for existence of any file matching a mask, instead of a specific file, enable ''[[scriptcommand_option#failonnomatch|option failonnomatch on]]'' mode and use ''[[scriptcommand_ls|ls mask]]'' command, instead of ''stat name'' command: | ||
Line 61: | Line 61: | ||
===== [[local]] Local file existence ===== | ===== [[local]] Local file existence ===== | ||
- | * In [[library_powershell|PowerShell]], use ''[[ps>microsoft.powershell.management/test-path|Test-Path]]'' cmdlet. See an example in [[library_example_check_existence_timestamp#powershell|Checking file existence and timestamp]]. | + | * In [[library_powershell|PowerShell]], use ''[[ps>microsoft.powershell.management/test-path|Test-Path]]'' cmdlet. See an example in [[library_example_check_existence_timestamp#powershell|*]]. |
- | * In a batch file, use ''[[https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/if|if exist]]'' command. See [[guide_automation_conditional#scripting|example]]. | + | * In a batch file, use ''[[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/if|if exist]]'' command. See [[guide_automation_conditional#scripting|example]]. |
- | * In .NET, use ''[[dotnet>system.io.file.exists|File.Exists]]'' method. See [[library_example_check_existence_timestamp#csharp|C#]] and [[library_example_check_existence_timestamp#vbnet|VB.NET]] example in [[library_example_check_existence_timestamp|Checking file existence and timestamp]]. | + | * In .NET, use ''[[dotnet>system.io.file.exists|File.Exists]]'' method. See [[library_example_check_existence_timestamp#csharp|C#]] and [[library_example_check_existence_timestamp#vbnet|VB.NET]] example in [[library_example_check_existence_timestamp|*]]. |
- | * In WSH, use ''[[https://msdn.microsoft.com/en-us/library/x23stk5t.aspx|Scripting.FileSystemObject.FileExists]]'' method. See [[library_example_check_existence_timestamp#jscript|JScript]] and [[library_example_check_existence_timestamp#vbscript|VBScript]] example in [[library_example_check_existence_timestamp|Checking file existence and timestamp]]. | + | * In WSH, use ''[[https://learn.microsoft.com/en-us/previous-versions/x23stk5t(v=vs.85)|Scripting.FileSystemObject.FileExists]]'' method. See [[library_example_check_existence_timestamp#jscript|JScript]] and [[library_example_check_existence_timestamp#vbscript|VBScript]] example in [[library_example_check_existence_timestamp|*]]. |
===== Further Reading ===== | ===== Further Reading ===== | ||
Line 70: | Line 70: | ||
* Guide to [[guide_automation|scripting/automation]]; | * Guide to [[guide_automation|scripting/automation]]; | ||
* [[library|WinSCP .NET assembly]]; | * [[library|WinSCP .NET assembly]]; | ||
- | * [[library_powershell|Using WinSCP .NET Assembly from PowerShell]]. | + | * [[library_powershell|*]]. |