QDir :: entryInfoList unexpected behavior

My code is pretty simple:

void DirManagement::listFiles(QDir dir) { QFileInfoList list = dir.entryInfoList(QDir::NoFilter, QDir::NoSort); for (int i = 0; i < list.size(); ++i) { QFileInfo fInfo = list.at(i); QString fPath = fInfo.absoluteFilePath(); qDebug() << "# " << i << fPath; } } 

The problem is that if my directory path is: "/ home / adasi / Desktop / GCUFolder" this is the result:

 # 0 "/home/Alya/Desktop/MCUFolder" # 1 "/home/Alya/Desktop" # 2 "/home/Alya/Desktop/MCUFolder/32Mon Oct 24 2011" # 3 "/home/Alya/Desktop/MCUFolder/32Sun Oct 23 2011" 

However, what I expect is ONLY according to this directory:

 # 0 "/home/Alya/Desktop/MCUFolder/32Mon Oct 24 2011" # 1 "/home/Alya/Desktop/MCUFolder/32Sun Oct 23 2011" 

I tried most qt filters. Does not work.

+4
source share
3 answers

Just add more information. It worked as Mat said, indicating that you want to list, for example:

 myQdirObject.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort); 
+9
source

Use the QDir::NoDotAndDotDot , this will remove the directory itself and its parent from the search.

+1
source

entryInfoList should be called using the filter QDir::NoDot | QDir::NoDotDot QDir::NoDot | QDir::NoDotDot :

 QFileInfoList list = dir.entryInfoList(QDir::NoDot | QDir::NoDotDot, QDir::NoSort); 

Check the relevant Qt documentation for additional filters.

0
source

All Articles