How to skip over or filter out "." and ".." from QDir?
-
I am using QDir to read all files in a directory:
QDir directory(dn); QStringList files = directory.entryList(); foreach(QString fn, files) processFile(dn + '/' + fn);
However I get the files "." and "..". How do I skip over these or filter them out?
This seems like a messy way of doing it:
if (fn != ".." && fn != ".") processFile(dn + '/' + fn);
-
If you go to google and type in QDir, the very first result points you to this really cool thing called on-line class documentation. ... Amazing! Give it a try.
-
@Guerrian said in How to skip over or filter out "." and ".." from QDir?:
if (fn != ".." && fn != ".")
It's the best solution. For me NoDotAndDotDot never works correctly (e.g directories having dot in name)
-
@damianatorrpm said in How to skip over or filter out "." and ".." from QDir?:
For me NoDotAndDotDot never works correctly (e.g directories having dot in name)
Because it only refers to . and .. not to files starting with .
-
@damianatorrpm This worked for me:
QDir directory(dn); QStringList files = directory.entryList(QDir::NoDotAndDotDot | QDir::AllEntries); foreach(QString fn, files) slvFl(dn + '/' + fn);