-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (43 loc) · 1.6 KB
/
main.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import shutil
from fs.common import Directory
from fs.ftype import FileType
from media.metadata import MetaFactory
path = input('Target path: ')
move_not_dated = True
if path.strip() == '':
path = os.path.abspath('./resources')
move_not_dated = False
print(f'Lookup directory: {path}')
dir_obj = Directory(path)
for file in dir_obj.fetch(FileType.list()):
print(f'-------- Processing file {file.name}')
print(f'#')
try:
file_meta = MetaFactory.factory(file)
date = file_meta.get_create_timestamp()
if date is not None:
print(f'Tagging file {file.basename} with date {date}')
file.create_timestamp = date
file.save()
else:
print(f'No date taken for file: {file.basename}')
if not move_not_dated:
continue
file_dir = os.path.dirname(file.name)
not_dated = os.path.join(file_dir, Directory.EXCLUDED_DIR_NAME)
if not os.path.isdir(not_dated):
os.mkdir(not_dated)
# making sure the file does not exist
new_filename = f'{not_dated}/{file.basename}'
while os.path.isfile(new_filename):
new_filename = f'{not_dated}/{file.create_unique_basename()}'
print(f'Copy from {file.name} to {new_filename}')
shutil.move(file.name, new_filename)
except ValueError as msg:
print(f'{file.name}: {msg}')
continue
finally:
print(f'#')
print(f'-------------- End processing for file {file.basename}----------------------')
print('')