Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get only files but not directories in QT?

Tags:

file

directory

qt

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?

like image 793
Mahesh Avatar asked Jul 15 '11 15:07

Mahesh


2 Answers

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

like image 166
Martin Beckett Avatar answered Oct 18 '22 21:10

Martin Beckett


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)

;

like image 30
pranavjayadev Avatar answered Oct 18 '22 21:10

pranavjayadev