[Qt-interest] QFile::exists on a folder

Mika Rajala mika_rajala_2 at hotmail.com
Thu Feb 11 14:02:31 CET 2010


> Indeed, but the OP was trying to open the file anyway. That's why I was 
> questioning why he was trying to figure out if a file existed before opening.


The reason why i used open was to check that the path didn't point to a folder. The actual reading and opening of the file would happen later in another process, i was merely trying to validate that i was giving it a file it could open.

 

> If a file cannot be opened, then it may be in his interest to check why that 
> happened, if it's a temporary condition or not.

 

Yes, i would like to gather any data about why the open operation failed, i.e. file didn't exist, no permission to open file, file parsing error or something. This so that it could be presented to the user.

 

The problem was that I messed up with files and directories. I didn't realize this:

 

QDir::exists() true if path is a folder, false if path is a file.

QFile::exists() true if path is a folder or a file.

 

It doesn't say it too clear in the documentation, atleast in my opinion.

 

QFile::exists

"Returns true if the file specified by fileName() exists; otherwise returns false."

 

QDir::exists

"Returns true if the directory exists; otherwise false. (If a file with the same name is found this function will return false)"

 

Now you might say that you should have known that all folders are files but not all files are folders. Yes, but this doesn't make the documentation any clearer. Since in the QDir::exists it says that if a file with the same name exists, false is returned. Now i'd like to think that the word "file" here refers to the same thing as in the documentation of QFile::exists, but it doesn't. QDir "file" refers to files which arent folders. QFile "file" refers to files, including those which are folders.

 

-mika
 		 	   		  
_________________________________________________________________
Windows Liven avulla voit jakaa valokuviasi helposti.
http://www.download.live.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100211/f888148b/attachment.html 


More information about the Qt-interest-old mailing list