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. Why QFile::exists return true value on three dots path (“…”)
QtWS25 Last Chance

Why QFile::exists return true value on three dots path (“…”)

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 3.1k 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.
  • S Offline
    S Offline
    Stramonium
    wrote on 3 Aug 2014, 14:06 last edited by
    #1

    Hello!

    Today I found that when checking file existence, QFile::exists always return true value on three dots path ("...").

    Does three dot's have some special meaning?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BlastDV
      wrote on 3 Aug 2014, 14:16 last edited by
      #2

      What Operating System are you using?

      If you run
      @cd ...
      @
      on Windows it will leave you on the same directory you are.
      If you do it on Linux it will move you 2 directories up on the directory tree. And one more every extra dot you put.

      QFile::exists() may be returning true on ("...") because as far as I know, directories are a special type of file, at least on UNIX based systems (which I think Linux and Mac OS are based on).

      So asking for ("...") file should always return true.

      (8) Just live your life blind like me (8)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        p3c0
        Moderators
        wrote on 3 Aug 2014, 14:19 last edited by
        #3

        I'm using Qt 5.3.1 on Ubuntu 13.04 and QFile::exists("...") returns false.

        [quote author="BlastDV" date="1407075374"]What Operating System are you using?

        If you run
        @cd ...
        @
        on Windows it will leave you on the same directory you are.
        If you do it on Linux it will move you 2 directories up on the directory tree. And one more every extra dot you put.

        QFile::exists() may be returning true on ("...") because as far as I know, directories are a special type of file, at least on UNIX based systems (which I think Linux and Mac OS are based on).

        So asking for ("...") file should always return true.[/quote]

        AFAIK, using cd ... wont work on Linux systems.

        157

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BlastDV
          wrote on 3 Aug 2014, 14:27 last edited by
          #4

          You are absolutely right p3c0, "cd ..." won't work on Linux.

          I said that because I misread an article about defining alias for directories in order to run them on the terminal as if they were commands. This is the "link":http://www.thegeekstuff.com/2008/10/6-awesome-linux-cd-command-hacks-productivity-tip3-for-geeks/ for that.

          (8) Just live your life blind like me (8)

          1 Reply Last reply
          0
          • P Offline
            P Offline
            p3c0
            Moderators
            wrote on 3 Aug 2014, 14:43 last edited by
            #5

            Hmm with alias anything is possible.
            That makes me think for the original question.

            bq. Why QFile::exists return true value on three dots path (“…”)

            Do you have a file named ... ? It would be a hidden file. May be the file is created accidently or it may be a symbolic link to another file ?

            157

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Stramonium
              wrote on 3 Aug 2014, 17:03 last edited by
              #6

              I use Win7 x64. No such file exists.

              http://i62.tinypic.com/15ogpdy.jpg

              I read for a while and I think the only the first dot does matter, because file from string "." also exists. So I suppose that qt just checks if current directory exists and returns true.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hskoglund
                wrote on 3 Aug 2014, 17:47 last edited by
                #7

                On Win98SE and WinME cd ... did work :-) i.e. you stepped up two directories

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andreyc
                  wrote on 4 Aug 2014, 05:28 last edited by
                  #8

                  What is result of QFileInfo::exists("...") ?
                  Is it possible that you have a link that is named "..." ?

                  The code below returns false for ... on Linux
                  @
                  #include <QCoreApplication>
                  #include <QFile>
                  #include <QDebug>
                  #include <QFileInfo>

                  int main(int argc, char *argv[])
                  {
                  QCoreApplication a(argc, argv);

                  QStringList fileNames;
                  fileNames << "...." << "..." << ".." << ".";
                  QFile file;
                  foreach (QString fileName, fileNames) {
                      file.setFileName(fileName);
                      qDebug() << file.fileName()
                               << file.exists()
                               << QFile::exists(fileName)
                               << QFileInfo::exists(fileName);
                  }
                  
                  return 0;
                  

                  }
                  @

                  1 Reply Last reply
                  0

                  1/8

                  3 Aug 2014, 14:06

                  • 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