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
QtWS25 Last Chance

[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 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 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 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 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 last edited by
            #5

            Why am I not right?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on 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 last edited by
                #7

                Thanks for the explanation and for the help!

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  ronM71
                  wrote on 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

                  • Login

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