Topic "ListDirectory.Files does not return collection when only one matching file"

Author Message


$directoryInfo = $session.ListDirectory($somePath)
$files = $directoryInfo.Files

When there is more than one file in $somePath, $files correctly contains a collection (RemoteFileInfoCollection) of files and $files.Length returns the number of files in the collection.

When there is only one file in $somePath, $files contains a single File object instead of a collection of one file. $files.Length returns the size of the file.

Using: SFTP, WinSCP 5.7.3 on Windows 8.1 and PowerShell
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26890
Location: Prague, Czechia
I do not think this is true. It's just how the PowerShell presents it. What does $files.GetType().FullName say?

Ntb, if you do $files.Length, it returns a collection of values returned by .Length property of collection items (it's a kind of magic). To get number of items in collection, use .Count.

You can post new topics in this forum


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!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License