integrate a rough check for duplicate files.
This is still very rough and can probably file at multiple points.
This commit is contained in:
parent
097675a9e8
commit
4d0ddb5b94
|
@ -21,6 +21,7 @@ Options:
|
||||||
import os
|
import os
|
||||||
import fnmatch
|
import fnmatch
|
||||||
from shutil import copy2
|
from shutil import copy2
|
||||||
|
import filecmp
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
@ -63,17 +64,32 @@ def copy_files(extensions, search_path, dest):
|
||||||
|
|
||||||
for file_type, files_by_type in path_dictionary.items():
|
for file_type, files_by_type in path_dictionary.items():
|
||||||
if files_by_type:
|
if files_by_type:
|
||||||
path = os.path.join(dest, file_type)
|
target_path = os.path.join(dest, file_type)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(target_path):
|
||||||
os.makedirs(path)
|
os.makedirs(target_path)
|
||||||
|
|
||||||
for file in files_by_type.items():
|
for source_path, file_name in files_by_type.items():
|
||||||
if not os.path.islink(file):
|
if os.path.islink(source_path):
|
||||||
try:
|
continue
|
||||||
copy2(file, path)
|
|
||||||
except Exception as e:
|
target_file = os.path.join(target_path, file_name)
|
||||||
print(e)
|
counter = 1
|
||||||
|
if os.path.exists(target_file):
|
||||||
|
if not filecmp.cmp(target_file, source_path):
|
||||||
|
split_file_name = file_name.split('.')
|
||||||
|
new_file_name = (split_file_name[0],
|
||||||
|
"-" + str(counter),
|
||||||
|
".",
|
||||||
|
split_file_name[1])
|
||||||
|
s = ""
|
||||||
|
file_name = s.join(new_file_name)
|
||||||
|
target_file = os.path.join(target_path, file_name)
|
||||||
|
counter += 1
|
||||||
|
copy2(source_path, target_file)
|
||||||
|
else:
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
copy2(source_path, target_file)
|
||||||
|
|
||||||
|
|
||||||
def sort_jpgs(location):
|
def sort_jpgs(location):
|
||||||
|
|
Reference in New Issue