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 = ""):
|
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!')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user