Spaces:
Paused
Paused
File size: 1,134 Bytes
eb5ec73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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 |