On windows, os.path.exists
returns true, no matter if the case of the argument matches the file name. However, on my Heroku deployed app, which runs on Unix, this is not the case - it returns False when a user for some reason uses upper case letters in the argument. I could work around this by having all files always in lowercase, and putting a .lower()
after the user input, but this is not the nicest way i feel. How can i ensure that when os.path.exists
compares input with files, it absolutely ignores case on the files? Lets say i get all files with os.listdir
and then iterate over the list, converting them all to lowercase and then matching the user input with that list. I want to do exactly that, but without having to do these extra steps, but with just using os.path.exist() - is that possible?
question from:
https://stackoverflow.com/questions/66049640/how-do-i-force-ignore-case-sensitivity-on-pythons-os-path-exist-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…