Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QFileInfo::isExecutable() returns true for dirs



  • I am using the following code to search all subdirs for executables.

    @QDir dir(path);
    QDirIterator iterator(dir.absolutePath(), QDirIterator::Subdirectories);
    while (iterator.hasNext()) {
    iterator.next();
    if(!iterator.fileInfo().isDir() && iterator.fileInfo().isExecutable()) {
    tests.append(new QFile(iterator.filePath()));
    qDebug() << iterator.filePath();
    emit locatedTest(iterator.fileName());
    }
    }@

    That works fine, however if i remove the isDir() check, all directories, including . and .., are printed aswell. Is this a bug, or is there some reason I don't understand?



  • Well, on Unix most directories are marked as executable which means that you have permission to 'change directory' in to the dir.

    For example 'ls -l' give following output:
    drwxr-xr-x+ ... Documents
    drwx------+ ... Downloads



  • Then there was in fact a reason I did not understand, many thanks!



  • You could try changing the permission on a directory to see if I'm right but I'm quite sure that this is the expected behavior.


Log in to reply