import os def check_existing_file(file_path): '''Check if a file already exists. If it does, ask if we want to overwrite it.''' if os.path.isfile(file_path): while True: response = input(f"File {os.path.basename(file_path)} already exists. Do you want to overwrite it? (y/n): ") if response.lower() == 'y': return True elif response.lower() == 'n': return False else: print("Invalid response. Please enter 'y' or 'n'.") else: return True def check_existing_folder(folder_path): '''Check if a folder already exists. If it does, ask if we want to create it.''' if os.path.exists(folder_path) == False : while True: response = input(f"{os.path.basename(folder_path)} doesn't exists. Do you want to create it? (y/n): ") if response.lower() == 'y': return True elif response.lower() == 'n': return False else: print("Invalid response. Please enter 'y' or 'n'.") else: return False