Post a reply

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: How to delete all files in a directory except the three most recent?

A reference to what specifically?
Everything is in the documentation:
https://winscp.net/eng/docs/
semomaf

Re: How to delete all files in a directory except the three most recent?

Thanks
I'm new in WinSCP. Is there any reference to help me?
martin

Re: How to delete all files in a directory except the three most recent?

Well, not with the simple scripting.
But with use of WinSCP .NET assembly from a PowerShell (or other) script, it's doable.
Something like this (but not tested):
$oldFiles =
    $session.ListDirectory($path) |
        Where-Object { -Not $_.IsDirectory } |
        Sort-Object -Property LastWriteTime -Descending |
        Select-Object -Skip 3
 
foreach ($oldFile in $oldFiles)
{
    $session.RemoveFile($transfer.FullName)
}
semomaf

How to delete all files in a directory except the three most recent?

Hi guys.
I want a script to delete old files on the remote site but remain the last three files whatever age file is.
Is this possible?