fsfwgen/utility/file_management.py

34 lines
1.0 KiB
Python
Raw Normal View History

2021-06-08 12:37:10 +02:00
# -*- coding: utf-8 -*-
import shutil
import os
def copy_file(filename: str, destination: str = "", delete_existing_file: bool = False):
if os.path.exists(filename):
try:
shutil.copy2(filename, destination)
except FileNotFoundError as error:
print("copy_file: File not found!")
print(error)
except shutil.SameFileError:
print("copy_file: Source and destination are the same!")
def move_file(file_name: str, destination: str = ""):
2021-07-31 20:07:41 +02:00
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!')