class FileHelper {

    public static Collection<File> wipeOldFiles(File directory, Long cutoffTime, boolean deleteDirectory) {
        if (directory == null || !directory.exists()) {
            return new ArrayList<File>();
        }

        Collection<File> result = new ArrayList<File>();
        Collection<File> oldFiles = FileHelper.getFilesOlderThan(directory, cutoffTime, Boolean.TRUE);
        for (File file : oldFiles) {
            String logString = "Deleting File: \"" + file.toString() + "\" ... ";

            if (file.canWrite() && file.delete()) {
                logString += "done. ";
                result.add(file);
                if (file.getParentFile().isDirectory()) {
                    if (file.getParentFile() != directory && file.getParentFile().delete()) {
                        log.info("Deleting Directory: \"" + file.getParent() + "\" ...  done");
                    } else if (file.getParentFile() == directory && deleteDirectory) {
                        log.info("Deleting Directory: \"" + file.getParent() + "\" ...  done");
                    }
                }
            } else {
                logString += "FAILED!";
            }
            log.info(logString);
        }

        return result;
    }

}