How to count files in FTP directory

Solution 1:

The $list contains:

file1`nfile2`nfile3`n

If you split the string by "`n", you (correctly) get four parts, with the last one being empty.

You can use an overload of String.Split that takes StringSplitOptions and use RemoveEmptyEntries:

$list.Split("`n", [System.StringSplitOptions]::RemoveEmptyEntries)