I have a small but itching problem. How do I get the correct case for a Windows path in Qt?
Let’s say i have a path c:\documents and settings\wolfgang\documents stored in a QString str and i want to know the correct case, here C:\Document and Settings\Wolfgang\Documents. QDir(str).absolutePath() doesn’t get me the path with correct case.
Any suggestions, since I have no clue what else i could try?
Thank you for your time!
There isn’t a simple way to do this, but you can try doing a
QDir::entryList, and then do a case insensitive search on the results. This will provide you with the correct filename. You’ll then need to do that for all folder levels up to the root.This should give you the preserved-case for the path/filename.
See emkey08’s answer for an example implementation.