glob like fuction to list all files in subfolders that match wildcard.
Basically want something similar to the python glob command.
glob("*/abc*.dat")
would search the first level of subfolders and give me string list of file paths for all files (from cwd) starting with "abc" ending with ".dat"
Is there a quick similar QT function?
Re: glob like fuction to list all files in subfolders that match wildcard.
Re: glob like fuction to list all files in subfolders that match wildcard.
I tried that but unless I am doing something wrong, I can't get it to list files in subfolders
If my folder structure is:
folder1/abc1.txt
folder1/xyz1.txt
folder1/abc2.txt
folder2/abc3.txt
folder2/xyz4.txt
folder3/abc5.txt
then if I give "*/abc*"
I'm looking for an output of
folder1/abc1.txt
folder1/abc2.txt
folder2/abc3.txt
folder3/abc5.txt
I tried entrylist but it just lets me filter on whats in the current folder
Re: glob like fuction to list all files in subfolders that match wildcard.
Quote:
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):
Code:
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;
}