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



  • 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?



  • 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.


  • Moderators

    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.



  • 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.


  • Moderators

    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 ?



  • 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.



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



  • 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;
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.