tags:

views:

64

answers:

2

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!

A: 

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 get the absolutePath for that result.

This should give you the preserved-case for the path/filename.

slomojo
Updated, a bit convoluted, but there's no nice simple way to do this unfortunately. -- I can't help wondering why you need a case-preserved path/filename on a case-insensitive filesystem?
slomojo
It's just for presenting the path to the user. They are used to correct cases of their paths.
Wolfgang Plaschg
How did the path end up all lower-case in the first place? I would rather fix that.
Frank
user entry I'm guessing from what Wolfgang has said.
slomojo
A: 

You can use QFileInfo for that and the function

QString QFileInfo::absoluteFilePath () const will return the absolute file path.

E.g:

QFileInfo yourFileInfo(yourPath);
QString correctedCasePath = yourFileInfo.absoluteFilePath ();

Another advantage is that, yourPath can be a QFile or QString so that you can use it directly with the handle currently you are having. Besides these, there are other operations are also available through QFileInfo that can obtain useful information about the file being referred to..

Hope it helps..

liaK
Sorry, it doesn't work on Windows. QFileInfo("c:/windows").absoluteFilePath() gives 'C:/windows' instead of 'C:/WINDOWS'.
Wolfgang Plaschg