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

Advertisement

cag8f
Joined:
Posts:
9

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

Hi all. I have a WinSCP script that automatically downloads a file from my remote directory to a local directory. This occurs once a week, and I would like to add additional code to my script so that my local directory keeps at most three such backups. How might I approach that? I gather the rough logic would be:

* Count number of files in local directory (this directory stores only these backup files--nothing else).
* If number of files is greater than three, delete the oldest file.

Thanks in advance.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,390
Location:
Prague, Czechia

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

Management of local files have nothing to do with WinSCP.

Reply with quote

Advertisement

You can post new topics in this forum