How to delete files older than X days

View some of the Frequently Asked Questions to our support staff. Included are some tips and tricks making this forum ideal for users getting started with GoAnywhere MFT. Note: Users can reply to existing topics but only our support staff can add new topics to this forum.
1 post Page 1 of 1

Support_Barrett

Posts: 2
Joined: Tue Apr 21, 2020 4:02 pm

Post by Support_Barrett » Wed Apr 22, 2020 4:59 pm
Q:
How can I delete files in a directory that are older than X days?

A:
Directories can occasionally get crowded by old, unnecessary files. GoAnywhere has a simple solution to this by making use of the Delete task.
Image
Here is a simple project to delete some files in my “output” directory. When the deletion is performed, the number of affected files will be outputted to the job log.

Adding a date filter allows you to select files between a certain age. In this instance, I only want files older than 30 days to be selected. The function I use is “${AdjustDateTime(CurrentDate('yyyy-MM-dd HH:mm:ss a'), 'yyyy-MM-dd HH:mm:ss a', 'days', -30)}”. This adjusts the specified time to be 30 days before today. You can find more information on the AdjustDateTime function here: manipulating-date-time-in-a-project-1406

Other fields:
• Base Directory: this is the directory that will be checked
• Include Items: choose whether files, directories, or both will be affected by the delete
• Recursive: if true, subdirectories will be searched in the deletion process

To make this process completely automated, you can have it run via Scheduler. I created one for my project that will run every Friday at 6:00pm:
Image
Setup is fairly simple, and now my directory is looking much neater.
1 post Page 1 of 1