Results 1 to 3 of 3

Thread: QFile::exists() and QFileInfo::exists() and case sensitive file names

  1. #1
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default QFile::exists() and QFileInfo::exists() and case sensitive file names

    Hi

    I need to check if a file exists in a folder, and that the file name actually matches the case of the search string. However on Windows QFile::exists() and/or QFileInfo::exists() does not take the case of the file name into account. I have not tested it but I suspect on Unix exists() will take the case of the file name into account.

    Is there any way to use the exists() function as on windows so that they take the case into account?

    I can probably do a manual check by looking at the file names in the directory using QDir, but I'm hoping there is an easier way.

    Thanks,
    Jaco
    Last edited by JPNaude; 21st February 2011 at 12:41.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::exists() and QFileInfo::exists() and case sensitive file names

    Windows filenames are not case sensitive.

    I think you cannot do this check because in Windows filename.txt and FileName.TXT are the same file
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: QFile::exists() and QFileInfo::exists() and case sensitive file names

    Yip I'm aware of that. I guess exists() uses the file system's case sensitivity. I need to check it on Windows since I generate scripts that's run on a Linux machine. The easiest way I could come up with its:

    Qt Code:
    1. bool FirmwareCore::FileModel::caseSensitiveExists() const {
    2. // Only do it if it says it exists;
    3. // exists() is a normal exists on QFileInfo
    4. if (exists()) {
    5. // Check the directory where the file is located:
    6. // fileInfo() below is a normal QFileInfo object.
    7. QDir parent_dir = fileInfo().dir();
    8. return parent_dir.entryList().contains(fileName(),Qt::CaseSensitive);
    9. } else
    10. return false;
    11. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. detect if a URL exists or not
    By timmu in forum Qt Programming
    Replies: 5
    Last Post: 27th January 2013, 14:16
  2. Check if item exists into listwidget
    By hakermania in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2011, 22:54
  3. Can't create folder if file with same name exists
    By Barry79 in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2009, 17:33
  4. qmake exists() function
    By roxton in forum Installation and Deployment
    Replies: 1
    Last Post: 28th December 2008, 20:43
  5. Does anyone know if anything like this exists for Qt
    By Jachyra in forum Qt Programming
    Replies: 3
    Last Post: 8th February 2007, 23:06

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.