Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
565 views
in CompleteFTP by (51.6k points)

A user asked us:

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

1 Answer

0 votes
by (51.6k points)
edited by
 
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.

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) {
    console.debug("Deleting old files from " + folder.fullPath);
    folder.getFiles().forEach(function (f) {
        console.debug("Found file " + f.fullPath);
        if (f.name.indexOf(".zip.folder") >= 0)
            return;
        if (f.isFolder) {
            deleteOldFiles(f);
            f.removeFolder();
        } else {
            var now = new Date();
            var msPerDay = 1000*60*60*24;
            var ageInDays = (now.getTime() - f.modifiedTime.getTime()) / msPerDay;
            if (ageInDays > maxAgeInDays) {
                console.debug("Deleting " + f.fullPath);
                f.removeFile();
            }
        }
    });
}

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

Categories

...