[Solved]QFile::exists return true when i choose folder
-
wrote on 26 Feb 2012, 17:01 last edited by
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. -
wrote on 26 Feb 2012, 17:13 last edited by
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. -
wrote on 27 Feb 2012, 09:01 last edited by
Hi, Just use QFileInfo mentioned above by Koahnig and combine use functions:
bool exists () const
bool isDir () const
bool isFile () const
bool isSymLink () const -
wrote on 27 Feb 2012, 09:17 last edited by
What makes you think a folder is not a file?
-
wrote on 27 Feb 2012, 09:49 last edited by
Why am I not right?
-
wrote on 27 Feb 2012, 09:53 last edited by
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 ) -
wrote on 27 Feb 2012, 10:08 last edited by
Thanks for the explanation and for the help!
-
wrote on 27 Feb 2012, 18:28 last edited by
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.
1/8