Topic "Test-Path -exclude equivalent for remote path."

Author Message
Guest




I'm wondering if there is a powershell:
Code:
test-path c:\* -exclude test.txt
equivalent for remote folders?

I know I can find the existence of one file using:

Code:
$remotePath = "/home/user/test.txt"
 
if ($session.FileExists($remotePath))
{
    Write-Host ("File {0} exists" -f $remotePath)
}


but I want to find out if 1 specific file exists only - in a specific folder. (basically: if there is more then the specified file, return true; if it's just the one file, return false)

Thanks.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
Code:
$files = $session.ListDirectory("/home/user").Files | Where-Object { (-not $_.IsDirectory) -and ($_.Name -ne "test.txt") }
if ($files)
{
    Write-Host "Files " $files " found"
}


See https://winscp.net/eng/docs/library_example_listing_files_matching_wildcard
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License