Move files to desired path

This commit is contained in:
Felipe Martin 2018-09-29 23:57:30 +02:00
parent 07f3d00c6e
commit 01cb50c632
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
1 changed files with 8 additions and 1 deletions

View File

@ -3,6 +3,7 @@ from datetime import datetime
import hashlib
import mimetypes
import os.path
import shutil
import subprocess
from typing import Text
@ -156,5 +157,11 @@ def get_target_path(fileobj):
if __name__ == '__main__':
for fileobj in read_path():
target_path = get_target_path(fileobj)
try:
target_path = get_target_path(fileobj)
except Exception as exc:
print(f'---- Error on {fileobj.path} ----')
print(exc)
new_filename = '.'.join([fileobj.datetime.strftime('%Y-%m-%d_%H-%M-%S'), fileobj.extension])
os.makedirs(target_path, exist_ok=True)
shutil.move(fileobj.path, os.path.join(target_path, new_filename))