more checks in move function
This commit is contained in:
parent
4b494ae07c
commit
2043b92cd4
@ -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!')
|
||||
|
Loading…
x
Reference in New Issue
Block a user