Site icon Ryadel

How to delete files older than X days from FTP server or folder with a batch file in Windows

How to map any FTP server and/or folder to a Windows drive letter using FTPUSE

If you've read this post of mine you already know about FTPUSE: a great command-line freeware tool that we can use to map a FTP server or folder to a Windows drive letter. Think of it as a Map Network Drive that accepts FTP addresses instead of UNC shares. Such powerful feature can be used to automate a lot of tasks that we usually can't do within FTP folders, such as - for example - deleting all the files older than X days.

Here's how we can do that with the help of FTPUSE, assuming we have it installed:

The batch file is quite self-explanatory: we map the FTP folder using FTPUSE, then we wait 5 seconds to give the system enough time to get it ready. Last but not least, we use the good old forfiles feature - which we already talked about here - to find and delete the files older than X days (7 in our example).

That's it for now: happy scripting!

 

Exit mobile version