QDir - Filter by file name, not extension
General and Desktop
4
Posts
3
Posters
5.4k
Views
1
Watching
-
I would like to list the files in a directory with similar names (not extension).
For example, list all files that sounds like "Apple". (Apple1.txt, Apple2.txt, Apple3.txt)
To list files by extension I would to this:
@
QStringList nameFilter("*.txt");
QDir directory("/home/");
QStringList FilesAndDirectories = directory.entryList(nameFilter);
@But how do I list by file name?
-
@
QStringList nameFilter("Apple*");
@ -
Your default filter is set to NoFilter!!
see definition:
QStringList QDir::entryList(const QStringList & nameFilters, Filters filters = NoFilter, SortFlags sort = NoSort) const
so you can specify the Filters see:
"QDir::Filters":http://qt-project.org/doc/qt-5/qdir.html#Filter-enumat the link is allso an example :-)
best regards
Harry