PDA

View Full Version : QString tmp="file.txt";QFile file(tmp); How do I obtain REAL filename?( FiLe.TxT )



georgep
27th March 2009, 16:34
i am on stincking windows. the filename is case insensitive. file.txt = FiLe.tXT
I need to match against a list of case insensitive file names (strings) and determine the real filename that exists in the sistem :

if file.exists("case-insensitive.txt") then tell me file.filename(the real one not case-insensitive)

QString tmp = "file.txt"; //will match FiLe.tXt which is OK
QFile file(tmp);
qDebug()<<file.fileName();
QFileInfo file_info(file);
file_info.absoluteFilePath(); // i want FiLE.tXt not file.txt

how do i obtain the real name that exists in the windows file system ?

wysota
27th March 2009, 17:34
I think the easiest solution would be to retrieve the directory the file is in, open it with QDir and use QDir::entryList() to list files in this directory. They will have 'real' names so matching the proper one will be easy (for example using QString::toLower()).

georgep
28th March 2009, 12:41
i did:

QDir director("C:\\Documents and Settings\\");
QStringList list ( director.entryList(QDir::Files,QDir::Name) ) ;


list.indexOf( QRegExp( "file.txt" ,Qt::CaseInsensitive) ) //i get the id of the REAL fie



it works, but, is this an ugly/bad way ?

wysota
28th March 2009, 15:37
Yes, it's an ugly way, but I doubt there is a better one so you have to stick with it.