How to check wether a path represented by a QString with german umlauts exists?
Posted
by MB
on Stack Overflow
See other posts from Stack Overflow
or by MB
Published on 2010-04-13T16:41:19Z
Indexed on
2010/04/13
16:43 UTC
Read the original article
Hit count: 242
Hey,
i get a QString which represents a directory from a QLineEdit. Now i want to check wether a certain file exists in this directory. But if i try this with os.path.exists and os.path.join and get in trouble when german umlauts occur in the directory path:
#the direcory coming from the user input in the QLineEdit
#i take this QString to the local 8-Bit encoding and then make
#a string from it
target_dir = str(lineEdit.text().toLocal8Bit())
#the file name that should be checked for
file_name = 'some-name.txt'
#this fails with a UnicodeDecodeError when a umlaut occurs in target_dir
os.path.exists(os.path.join(target_dir, file_name))
How would you check if the file exists, when you might encounter german umlauts?
© Stack Overflow or respective owner