Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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.
alien_technology

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