Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO

How do I have CompleteFTP delete files that are older than 14 days?

0 votes
84 views
asked Dec 21, 2016 in CompleteFTP by EDT Support (41,570 points)

A user asked us:

How do I have CompleteFTP delete files that are older than 14 days?

1 Answer

0 votes
answered Dec 21, 2016 by EDT Support (41,570 points)
edited Dec 21, 2016 by EDT Support
 
Best answer

You could use a scheduled process trigger to periodically call a JSS script that iterates through a folder-tree deleting any files that are older than 14 days.

Something like the following should do the trick:

Inline images 1

Here's the script so that you can copy-and paste:

 

var maxAgeInDays = 14;
var baseFolder = "/Home";

// Deletes all files in the given folder (and all its sub-folders)
// that are older than maxAgeDays
function deleteOldFiles(folder) {
    folder.getFiles().forEach(function(f) {
        if (f.isFolder())
            deleteOldFiles(f);
        else {
            var now = new Date();
            var msPerDay = 1000*60*60*24;
            var ageInDays = (now.getTime() - f.modifiedTime.getTime()) / msPerDay;
            if (ageInDays > maxAgeInDays)
                f.removeFile();
        }
    }
}

// Call removeOldFiles on the base folder
deleteOldFiles(system.getFile(baseFolder));
...