I have a list of files on an FTP server that I am saving to a local drive. I'm also renaming the files based on their file extension. How can I save the files so that they overwrite any existing files but also rename in sequence, so if there are multiple files of the same extension they would be named ext.txt ext2.txt ext3.txt, etc? My code currently is overwriting files so that I end up with only 1 file per extension. Here's the relevant bit:
$myfiles | ForEach-Object{
$extension = ([System.IO.Path]::GetExtension($_.Name)).Trim(".")
$session.GetFiles($session.EscapeFileMask($remotePath + $_.Name),
"$localPath\$extension.txt" ).Check()
}