[Solved]QFile::exists return true when i choose folder
-
Hello!
Why QFile::exists return true when i choose folder?
For example
@ if(QFile::exists("C:\Games"))
return true;@
C:\Games is folder not a file. -
You may want to use "QFileInfo":http://developer.qt.nokia.com/doc/qt-4.8/qfileinfo.html#exists instead.
There you can check whether it is a file or directory/folder. -
Hi, Just use QFileInfo mentioned above by Koahnig and combine use functions:
bool exists () const
bool isDir () const
bool isFile () const
bool isSymLink () const -
What makes you think a folder is not a file?
-
Why am I not right?
-
Because there are many different file systems, and in some of the ones used on Linux for instance a directory is a file.
[quote]A Linux system, just like UNIX, makes no difference between a file and a directory, since a directory is just a file containing names of other files. Programs, services, texts, images, and so forth, are all files. Input and output devices, and generally all devices, are considered to be files, according to the system.[/quote]
(from http://tldp.org/LDP/intro-linux/html/sect_03_01.html ) -
Thanks for the explanation and for the help!
-
I guess QFile was a more friendly name than QFileSystemElement. The name may suggest it only deals with what's perceived to the end-user as "files", but it does folders too.