aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Liodden <[email protected]>2017-12-18 17:51:46 +0100
committerErik Liodden <[email protected]>2017-12-18 17:51:46 +0100
commited1aac5a07b91146f2bf14f0fa192f3e8c2caa60 (patch)
tree8f0da0d9cc81934356dcc6ad9343a8eb7d6c7ac0
parent557ab029e753f4ff6d3ed9ec875864efe45b792d (diff)
downloadboil-me-baby-ed1aac5a07b91146f2bf14f0fa192f3e8c2caa60.tar.gz
put files older than 4 years in a separate folder
as the title says. this can be added to the bash scripts.
-rw-r--r--min4.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/min4.py b/min4.py
new file mode 100644
index 0000000..081dfaa
--- /dev/null
+++ b/min4.py
@@ -0,0 +1,36 @@
+# min4.py
+#
+# put files older than 4 years in a separate folder
+# erik liodden
+
+import os
+from subprocess import call
+import glob
+from datetime import datetime
+
+_OLD = datetime.now().year - 4
+
+def organise_dir(directory):
+ d = next(os.walk(directory))[1]
+ candidates = []
+
+ for sd in d:
+ if sd != 'older' and int(sd[:-1]) < _OLD:
+ candidates.append(sd)
+
+ if candidates:
+ call(['mkdir', '-p', directory + '/older'])
+ for c in candidates:
+ src = f"./{directory}/{c}/"
+ dst = f"./{directory}/older/"
+ call(['rsync', '-a', '--ignore-existing', src, dst])
+ call(['rm', '-rf', src])
+
+def main():
+ d = next(os.walk('.'))[1]
+ for sd in d:
+ organise_dir(sd)
+ return 0
+
+if __name__ == '__main__':
+ main()