Skip to content
Snippets Groups Projects
Commit 981f749b authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Use shutil instead of os.rename

parent 4aea1caf
No related branches found
No related tags found
No related merge requests found
import os
import shutil
def rename_file(instance, field_name, new_name, allow_missing_file=False):
......@@ -7,7 +8,7 @@ def rename_file(instance, field_name, new_name, allow_missing_file=False):
new_name_with_extension = '{}{}'.format(new_name, extension)
try:
os.rename(field.path, new_name_with_extension)
shutil.move(field.path, new_name_with_extension)
except FileNotFoundError:
if not allow_missing_file:
raise
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment