Results 1 to 4 of 4

Thread: QFile::exists(name) verifies PATH to name, but not only FILE name existence

  1. #1
    Join Date
    Mar 2015
    Posts
    2
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default QFile::exists(name) verifies PATH to name, but not only FILE name existence

    On my Windows platform, I have noticed that QFile::exists(name) returns true in case "name" is a directory name, but not a file.
    So, it means this method verifies PATH existence, but not a file existence. This is not what is in manual.
    Am I missing something here?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QFile::exists(name) verifies PATH to name, but not only FILE name existence

    I see what you are referring to. Not sure if it's a bug in the code or incorrect doc. Either way, use QFileInfo and you can check both the existence and isFile or isDir, etc.

  3. #3
    Join Date
    Mar 2015
    Posts
    2
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default Re: QFile::exists(name) verifies PATH to name, but not only FILE name existence

    Yes,
    thanks
    I know that
    But instead of using to calls (isDir() and isFile()), I can use just one QFile.exists() in order to learn if path is does not exist.
    But I am afraid it will not work always, because it is AGAINST the manual, which said QFile.exists() will return false if FILE does not exists. So, the fact that it returns TRUE if DIRECTORY exists it could be a bug or platform dependence or may be bad overload somewhere...
    That is my question: is it expected behavior from QFile.exists() return true on DIRECTORY existence and return false on FILE or DIRECTORY absence - practically verifies path existence instead of file existence.

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QFile::exists(name) verifies PATH to name, but not only FILE name existence

    It makes sense on some level that passing a directory name (or file name) to QFile::exists() returns true if the item exists. If you wanted to guarantee that the item exists *and* is a file, you'd have to do as I suggested in my first post.

    If you feel that this is a bug, I'd recommend that you submit a bug report.

    Good luck.

Similar Threads

  1. QFile::exists( filename ) slow
    By lni in forum Qt Programming
    Replies: 9
    Last Post: 25th February 2015, 23:19
  2. Replies: 3
    Last Post: 19th September 2014, 07:23
  3. Checking the existence of a symbolic link file
    By ofer88 in forum Qt Programming
    Replies: 7
    Last Post: 15th July 2012, 21:17
  4. Replies: 3
    Last Post: 9th August 2011, 08:37
  5. Replies: 2
    Last Post: 21st February 2011, 14:52

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.