Download Jar. Libraryless. Click here for Pure Java version (3905L/25K).
!7 sS progID = #1007510; sbool doIt; p { if (eq(first(args), "doit")) doIt = true; new L<File> files; new Map<File, Double> 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; }
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): cfunsshuasjs, jtubtzbbkimh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1011258 |
Snippet name: | Thin a program's backups (-> thinAProgramsBackups) |
Eternal ID of this version: | #1011258/16 |
Text MD5: | 0609036064366917f958b95b62382bc3 |
Transpilation MD5: | bce6056b31089a8506e7f4ca5ff0bfb6 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | Yes |
Created/modified: | 2017-10-21 22:18:43 |
Source code size: | 1542 bytes / 56 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 501 / 1055 |
Version history: | 15 change(s) |
Referenced in: | #1011269 - thinAProgramsBackups - keeps all hourly backups in last 2 days, one per day in last 31 days, one per week after #1011271 - Thin all programs' backups [OK, invoke with "doit"] |