!7 sS progID = #1007510; sbool doIt; p { if (eq(first(args), "doit")) doIt = true; new L files; new Map ageMap; Pattern pat = Pattern.compile("^(.*)\\.backup(20\\d\\d)(\\d\\d)(\\d\\d)-(\\d\\d)$"); for (File f : listFilesNotDirs(programDir(progID))) { S s = f.getName(); Matcher matcher = pat.matcher(s); continue unless matcher.find(); S originalName = matcher.group(1); continue unless eq(originalName, "concepts.structure.gz"); //print("Found backup: " + sfu(matcherGroups(matcher))); int year = matcherInt(matcher, 2); int month = matcherInt(matcher, 3); int day = matcherInt(matcher, 4); int hour = matcherInt(matcher, 5); long time = timestampFromYMDH(year, month, day, hour); double age = ((now()-time)/1000.0/60/60/24; //print("Age: " + age + " days"); ageMap.put(f, age); files.add(f); } int numDeleted = 0; sortByMap_inPlace(files, ageMap); double lastAge = -1; for (File f : files) { double age = ageMap.get(f); if (!shouldKeep(age, lastAge)) { //print("Deleting: " + f); ++numDeleted; if (doIt) { print("Deleting: " + f); f.delete(); } } else { print("Keeping: " + f); lastAge = age; } } print((doIt ? "Deleted: " : "Would delete: ") + n(numDeleted, "file")); } // age = age in days sbool shouldKeep(double age, double lastAge) { if (age <= 2) true; if (age >= lastAge+1) true; false; }