Get only files but not directories in QT?
20,773
Solution 1
Use QDir::entryInfoList to return a list of QFileInfo objectsd and then check the state of each of them, you can also use filters to only return a list of files /and/or dirs
Solution 2
Use this
QDir recoredDir("YOUR DIRECTORY");
QStringList allFiles = recoredDir.entryList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst);//(QDir::Filter::Files,QDir::SortFlag::NoSort)
;
Author by
Mahesh
Updated on August 10, 2022Comments
-
Mahesh almost 2 years
When I do this:
QDir myDir("/home/some/location"); QStringList filesList = myDir.entryList("*");
it is returning both the files and the directories inside that location. But I want only files. And the files can have arbitrary extensions. Any ideas?
-
James over 9 yearsThis gets directories too (on my Windows machine)
-
pranavjayadev over 9 yearsIn blackberry 10 devices it will return only files.