
Originally Posted by
enricong
I tried that but unless I am doing something wrong, I can't get it to list files in subfolders
What filter(s) are you specifying for QDir::entryList or QDir::entryInfoList?
The entryInfoList and entryInfo methods only operate on the directory path represented by the QDir variable instance. If you want to process sub-directories, you need to ask to receive directory entries *and* files and recurse into the sub-directories as well.
I'd suggest something like this (I have not compiled or tested this, it's only from memory):
void process_dir
(const QString &path
) {
name_filters << "abc*";
QFileInfoList fil
= dir.
entryInfoList(name_filters,
QDir::NoDotAndDotDot|QDir
::AllDirs|QDir
::Files);
for (int i = 0; i < fil.size(); i++)
{
if (fi.isDir())
process_dir(fi.absolutePath());
if (fi.isFile())
do_something_with_file(fi);
}
return;
}
void process_dir(const QString &path)
{
QDir dir(path);
QStringList name_filters;
name_filters << "abc*";
QFileInfoList fil = dir.entryInfoList(name_filters, QDir::NoDotAndDotDot|QDir::AllDirs|QDir::Files);
for (int i = 0; i < fil.size(); i++)
{
QFileInfo fi = fil.at(i);
if (fi.isDir())
process_dir(fi.absolutePath());
if (fi.isFile())
do_something_with_file(fi);
}
return;
}
To copy to clipboard, switch view to plain text mode
Bookmarks