more checks in move function

This commit is contained in:
Robin Müller 2021-07-31 20:07:41 +02:00
parent 4b494ae07c
commit 2043b92cd4
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
1 changed files with 16 additions and 7 deletions

View File

@ -15,10 +15,19 @@ def copy_file(filename: str, destination: str = "", delete_existing_file: bool =
def move_file(file_name: str, destination: str = ""):
if os.path.exists(file_name):
try:
shutil.copy2(file_name, destination)
os.remove(file_name)
except FileNotFoundError as error:
print("File not found!")
print(error)
if not os.path.exists(file_name):
print(f'move_file: File {file_name} does not exist')
return
if not os.path.exists(destination):
print(f'move_file: Destination directory {destination} does not exist')
return
try:
shutil.copy2(file_name, destination)
os.remove(file_name)
return
except FileNotFoundError as error:
print(error)
print('move_file: File not found')
except shutil.SameFileError as error:
print(error)
print('move_file: Files are the same!')