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

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 = ""): def move_file(file_name: str, destination: str = ""):
if os.path.exists(file_name): if not os.path.exists(file_name):
try: print(f'move_file: File {file_name} does not exist')
shutil.copy2(file_name, destination) return
os.remove(file_name) if not os.path.exists(destination):
except FileNotFoundError as error: print(f'move_file: Destination directory {destination} does not exist')
print("File not found!") return
print(error) 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!')