PDA

View Full Version : QFile::exists(name) verifies PATH to name, but not only FILE name existence



greglik
17th March 2015, 18:04
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?

jefftee
17th March 2015, 20:23
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.

greglik
17th March 2015, 22:29
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.

jefftee
17th March 2015, 22:42
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 (https://bugreports.qt.io/secure/Dashboard.jspa).

Good luck.