Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
Posts: 5
Registered: ‎04-18-2013
My Device: PlayBook 16GB, White Z10
My Carrier: Airtel

How to read all files in a folder with QDir::entryList() ?

What's the best way to read all files in a folder using QDir:entryList or other methods, entryList() sometimes returns an empty list even when there are files in the folder, or am I missing something here?

Developer
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: How to read all files in a folder with QDir::entryList() ?

I suggest you use entryInfoList instead of entryList cause you will have more options with QFileInfo

very simple example get all files/folders inside folder

QDir dir("path to directory");

QFileInfoList files = dir.entryInfoList();
foreach (QFileInfo file, files){
    if (file.isDir()){
        qDebug() << "DIR: " << file.fileName();
    }else{
        qDebug() << "FILE: " << file.fileName();
    }
}

Also you can specify which files you want to get with QDir::Filters or sorting etc...

Hope it helps



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
New Contributor
Posts: 5
Registered: ‎04-18-2013
My Device: PlayBook 16GB, White Z10
My Carrier: Airtel

Re: How to read all files in a folder with QDir::entryList() ?

[ Edited ]

entyInfoList() works fine in the simulator, but on the device I only get "." and ".." entries, no files. 

Developer
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: How to read all files in a folder with QDir::entryList() ?

[ Edited ]

Play with filters :smileywink:

QFileInfoList list = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries);

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog