Results 1 to 4 of 4

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

  1. #1
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Red face QString tmp="file.txt";QFile file(tmp); How do I obtain REAL filename?( FiLe.TxT )

    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

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

    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()).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2008
    Location
    Europe
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

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

    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 ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

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

    Yes, it's an ugly way, but I doubt there is a better one so you have to stick with it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 18:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.