Download Jar. Libraryless. Click here for Pure Java version (3905L/25K).
1 | !7 |
2 | |
3 | sS progID = #1007510; |
4 | sbool doIt; |
5 | |
6 | p { |
7 | if (eq(first(args), "doit")) doIt = true; |
8 | |
9 | new L<File> files; |
10 | new Map<File, Double> ageMap; |
11 | |
12 | Pattern pat = Pattern.compile("^(.*)\\.backup(20\\d\\d)(\\d\\d)(\\d\\d)-(\\d\\d)$"); |
13 | for (File f : listFilesNotDirs(programDir(progID))) { |
14 | S s = f.getName(); |
15 | Matcher matcher = pat.matcher(s); |
16 | continue unless matcher.find(); |
17 | S originalName = matcher.group(1); |
18 | continue unless eq(originalName, "concepts.structure.gz"); |
19 | //print("Found backup: " + sfu(matcherGroups(matcher))); |
20 | int year = matcherInt(matcher, 2); |
21 | int month = matcherInt(matcher, 3); |
22 | int day = matcherInt(matcher, 4); |
23 | int hour = matcherInt(matcher, 5); |
24 | long time = timestampFromYMDH(year, month, day, hour); |
25 | double age = ((now()-time)/1000.0/60/60/24; |
26 | //print("Age: " + age + " days"); |
27 | ageMap.put(f, age); |
28 | files.add(f); |
29 | } |
30 | |
31 | int numDeleted = 0; |
32 | sortByMap_inPlace(files, ageMap); |
33 | double lastAge = -1; |
34 | for (File f : files) { |
35 | double age = ageMap.get(f); |
36 | if (!shouldKeep(age, lastAge)) { |
37 | //print("Deleting: " + f); |
38 | ++numDeleted; |
39 | if (doIt) { |
40 | print("Deleting: " + f); |
41 | f.delete(); |
42 | } |
43 | } else { |
44 | print("Keeping: " + f); |
45 | lastAge = age; |
46 | } |
47 | } |
48 | print((doIt ? "Deleted: " : "Would delete: ") + n(numDeleted, "file")); |
49 | } |
50 | |
51 | // age = age in days |
52 | sbool shouldKeep(double age, double lastAge) { |
53 | if (age <= 2) true; |
54 | if (age >= lastAge+1) true; |
55 | false; |
56 | } |
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: | 500 / 1051 |
Version history: | 15 change(s) |
Referenced in: | [show references] |