Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from rcdailey/move-to-samba-mount
Browse files Browse the repository at this point in the history
fixed: possible failure if the target directory was a SAMBA share on NTFS partition
  • Loading branch information
hugbug committed Sep 2, 2015
2 parents 10bef90 + 4944f94 commit 575cb5b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions VideoSort.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,22 @@ def unique_name(new):
suffix_num += 1
return new_name

def optimized_move(old, new):
try:
os.rename(old, new)
except OSError as ex:
print('[DETAIL] Rename failed ({}), performing copy: {}'.format(ex, new))
shutil.copyfile(old, new)
os.remove(old)

def rename(old, new):
""" Moves the file to its sorted location.
It creates any necessary directories to place the new file and moves it.
"""
if os.path.exists(new) or new in moved_dst_files:
if overwrite and new not in moved_dst_files:
os.remove(new)
shutil.move(old, new)
optimized_move(old, new)
print('[INFO] Overwrote: %s' % new)
else:
# rename to filename.(2).ext, filename.(3).ext, etc.
Expand All @@ -401,7 +409,7 @@ def rename(old, new):
if not preview:
if not os.path.exists(os.path.dirname(new)):
os.makedirs(os.path.dirname(new))
shutil.move(old, new)
optimized_move(old, new)
print('[INFO] Moved: %s' % new)
moved_src_files.append(old)
moved_dst_files.append(new)
Expand Down

0 comments on commit 575cb5b

Please sign in to comment.