Differences
This shows you the differences between the selected revisions of the page.
2014-11-06 | 2014-11-06 | ||
rewording (martin) | we actually have wildcard sample already (martin) | ||
Line 402: | Line 402: | ||
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 need to use ''Session.ListDirectory'' and [[library_example_listing_files_matching_wildcard|query returned list of files]]. | ||
~~AD~~ | ~~AD~~ | ||
- | |||
- | === [[mask]] Test remote files existence using wildcard === | ||
- | |||
- | If you are not looking for a specific file, but for any file matching a mask (e.g. ''*.txt''), you need to use ''[[library_session_listdirectory|Session.ListDirectory]]'' and query returned list of files. | ||
- | |||
- | <code powershell> | ||
- | $remoteDir = "/home/user" | ||
- | $wildcard = "*.txt" | ||
- | |||
- | $directoryInfo = $session.ListDirectory($remoteDir); | ||
- | |||
- | $matchingFiles = | ||
- | $directoryInfo.Files | | ||
- | Where-Object { $_.Name -Like $wildcard } | ||
- | |||
- | if ($matchingFiles) | ||
- | { | ||
- | Write-Host "Found $matchingFiles" | ||
- | } | ||
- | else | ||
- | { | ||
- | Write-Host "No matching files" | ||
- | } | ||
- | </code> | ||
- | |||
- | The ''-Like'' operator supports ''*'', ''?'' and ''[]'' patterns in the [[http://technet.microsoft.com/en-us/library/hh847812.aspx|wildcard]]. You can also use ''-Match'' operator with a regular expression. Learn about [[http://technet.microsoft.com/en-us/library/hh847759.aspx|PowerShell comparison operators]] | ||
=== [[scripting]] Using WinSCP Scripting === | === [[scripting]] Using WinSCP Scripting === |