The .
and ..
are references to this and parent directories respectively on most file systems.
To filter them, you can use new properties .IsThisDirectory
and .IsParentDirectory
of the RemoteFileInfo
class:
filesCount =
session.ListDirectory(DataFile.sRemoteDirectory).Files
.Where(file => !file.IsThisDirectory && !file.IsParentDirectory).Count();
Note that you have to use the Enumerable.Count()
extension method, instead of the ICollection.Count
property as the result of the Enumerable.Where()
is the IEnumerable
, not the Collection
anymore.
Or to make it even easier, use the Session.EnumerateRemoteFiles()
method, which with the EnumerationOptions.None
option is functionally equivalent to the Session.ListDirectory()
, just that it excludes the .
and ..
.
filesCount =
session.EnumerateRemoteFiles(
DataFile.sRemoteDirectory, null, EnumerationOptions.None).Count();
If you want to filter all directories, use:
filesCount =
session.ListDirectory(DataFile.sRemoteDirectory).Files
.Where(file => !file.IsDirectory).Count();