Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I do not need dot and dotdot

Tags:

c++

qt

when I list entries via QDir::entryInfoList I'm getting two extra entries, one with dot and second one with two dots. If I set QDir::NoDot and QDir::NoDotDot then nothing is listed. I need just the contents of the folder I'm passing to QDir, nothing else.

 QFileInfo fi(model_->filePath(e));
        auto file_path = fi.absoluteFilePath();
        auto lyst = QDir(fi.absoluteFilePath()).entryInfoList(/*QDir::NoDotAndDotDot makes lyst empty*/);
        foreach (QFileInfo info , lyst)
        {
            qDebug() << info.absoluteFilePath();
        }
like image 386
smallB Avatar asked Mar 26 '26 23:03

smallB


2 Answers

Pass QDir::NoDotAndDotDot filter ORed with QDir::Files or anything of your interest to entryInfoList

auto lyst =
 QDir(fi.absoluteFilePath()).entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries);
like image 189
parapura rajkumar Avatar answered Mar 29 '26 12:03

parapura rajkumar


According to this post:

The default value for the filter flags is QDir::AllEntries. When you override the default flags with QDir::setFlags or QDir::entryList, you should not forget to include at least one of QDir::Dirs, QDir::Files, or QDir::Drives to get any entries.

I imagine your code would look like this (haven't tested it):

QFileInfo fi(model_->filePath(e));
auto file_path = fi.absoluteFilePath();
auto lyst = QDir(fi.absoluteFilePath()).entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files);
foreach (QFileInfo info , lyst)
{
    qDebug() << info.absoluteFilePath();
}
like image 44
karlphillip Avatar answered Mar 29 '26 13:03

karlphillip