Use shutil.rename if on the same filesystem (move makes a copy first).

Suggested by the Python 2.6.4 documentation:
http://docs.python.org/library/shutil.html
This commit is contained in:
2010-01-21 09:38:35 +00:00
parent 124b442709
commit 90033e4169

View File

@@ -23,7 +23,7 @@ regex_config={}
# Path configs # Path configs
# Where to move the files # Where to move the files
config['target_path'] = "/Volumes/ionDrive/video/tv/%(file_showname)s/season %(seasno)s/" config['target_path'] = "/mnt/vault/video/TV Shows/%(file_showname)s/Season %(seasno)s/"
############################################## ##############################################
@@ -232,7 +232,8 @@ def make_path(path):
try: try:
os.makedirs(path) os.makedirs(path)
except OSError: except OSError:
print "Couldn't make path" #print "Couldn't make path"
pass
#end make_path #end make_path
def does_file_exist(path): def does_file_exist(path):
@@ -274,7 +275,7 @@ def main():
print "Old path:", oldfile print "Old path:", oldfile
print "New path:", newfile print "New path:", newfile
ans=confirm() ans= "always"
if ans == "always": opts.always = True if ans == "always": opts.always = True
if ans or opts.always: if ans or opts.always:
@@ -286,14 +287,14 @@ def main():
if same_partition(oldfile, newpath): if same_partition(oldfile, newpath):
print "[*] Moving file" print "[*] Moving file"
try: try:
shutil.move(oldfile, newpath) shutil.rename(oldfile, newpath)
except Exception, errormsg: except Exception, errormsg:
print "[!] Error moving file! %s" % (errormsg) print "[!] Error moving file! %s" % (errormsg)
#end try #end try
else: else:
print "[*] Copying file" print "[*] Copying file"
try: try:
copy_with_prog(oldfile, newfile) shutil.move(oldfile, newfile)
except Exception, errormsg: except Exception, errormsg:
print "[!] Error copying file! %s" % (errormsg) print "[!] Error copying file! %s" % (errormsg)
else: else: