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

Advertisement

alien_technology
Guest

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

Code:
$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.

Problem:
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

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Re: ListDirectory.Files does not return collection when only one matching file

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.

Reply with quote

Advertisement

You can post new topics in this forum