aboutsummaryrefslogtreecommitdiffstats
path: root/min4.py
blob: 081dfaa02cd065fbbef17de820edb6a9c796a11c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()