Hey, guys i have a problem, im building a simple notes program that creates text files which should function as notes. My current problem is that when I try to create a note with the same name as already existing note the error message wont show up for some reason.
Any ideas why ?
running = True
def mainMenu():
print('1. Create a new note.')
print('2. Delete a note.')
print('3. Exit a program.')
print()
choice = input('Enter a number of your choice: ')
handleMainMenu(choice)
def handleMainMenu(choice):
global running
if choice == '1':
note_name = input('Enter a name of your new note: ')
createNote(note_name)
elif choice == '3':
running = False
def createNote(note_name):
note_name = f"{note_name}.txt"
new_note_path = os.path.join(notes_path, note_name)
if not os.path.exists(new_note_path):
with open(new_note_path, 'w') as file:
file.write('')
print(f"Note '{note_name}' created successfully.")
else:
print('ERROR: Note with this name already exists!')
folder_path = 'C:/Users/maxov/Desktop/projects/python'
folder_name = 'notes'
notes_path = os.path.join(folder_path, folder_name)
if(not os.path.exists(notes_path)):
os.mkdir(notes_path)
while running:
mainMenu()