I know this has been asked before and I have searched online and read some of the related articles here on the forum for counting files. I have tried most of them and end with some error or the other. The most common error is
Cannot Find an overload for EnumerateRemoteFiles and the argument count: "2"
I saw another article where this error was brought up and Martin addressed it, but I could not quite make out what he was asking to implement and the person who asked the question, did not comment on that final help provided :(
I tried different iterations of the script and this one gets me a file count, but not in the format that I want. The output comes out like this – and count is correct.
Number of files in /Test/ is 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
I would like to get an output in this format:
and so on. (if that is not possible, then the total count of all files is enough)
Thank you for your input.
Here is the script that I tried, which gave the above output:
#Load WinSCP assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Session settings
$sessionOptions = New-Object WinSCP.SessionOptions -property{
# all the usual stuff
}
# Create session and connect
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)
# Remote directory to count files in
$remoteDirectory = "/Test/"
# Enumerate files and count them recursively
$fileCount =
$session.EnumerateRemoteFiles(
$remoteDirectory, "*.*", [WinSCP.EnumerationOptions]::AllDirectories).Count
# Close session
$session.Dispose()
# Output the count
Write-Host "Number of files in $remoteDirectory is $fileCount"