I want the user to enter a path to a directory as input. The program should check if this path really exists. If the path exists it should execute the rest of the code.
If the path does not exist it should print that it is a non existing path and I want it to request the user again to input a path, until the user enters a path that exists.
I have tried it with a while loop, with try and except and with if and else statements but I can't get it error free.
This is my current code:
i = 0
while i<1:
input = input("Please enter path to directory: ")
if os.path.exists(input) == False:
print("This path does not exist")
elif os.path.exists(input) == True:
os.chdir(input)
execute_code(input)
i +=1
If the user enters an existing path everything works fine, but if the path does not exist it prints that the path does not exist but it will show an error and will not request again for input.
What do I need to change so the program will ask the user again for input?