Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]QFile::exists return true when i choose folder
Forum Update on Monday, May 27th 2025

[Solved]QFile::exists return true when i choose folder

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 13.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ruzik
    wrote on 26 Feb 2012, 17:01 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on 26 Feb 2012, 17:13 last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        foxyz
        wrote on 27 Feb 2012, 09:01 last edited by
        #3

        Hi, Just use QFileInfo mentioned above by Koahnig and combine use functions:
        bool exists () const
        bool isDir () const
        bool isFile () const
        bool isSymLink () const

        I just know coding and coding

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 27 Feb 2012, 09:17 last edited by
          #4

          What makes you think a folder is not a file?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Ruzik
            wrote on 27 Feb 2012, 09:49 last edited by
            #5

            Why am I not right?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on 27 Feb 2012, 09:53 last edited by
              #6

              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 )

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Ruzik
                wrote on 27 Feb 2012, 10:08 last edited by
                #7

                Thanks for the explanation and for the help!

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  ronM71
                  wrote on 27 Feb 2012, 18:28 last edited by
                  #8

                  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 Reply Last reply
                  0

                  1/8

                  26 Feb 2012, 17:01

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved