-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.9.2
-
None
If I am interested in recursively finding hidden files in non-hidden directories or vice versa, I cannot express that using QDirListing.
Consider the following directory layout in a Linux system:
./subdir ./subdir/.file1.txt ./.subdir ./.subdir/.file2.txt
I want to gather all files starting with a dot, but not descend into directories starting with a dot.
The following piece of code will either find too many files or none, depending on whether I specify the "hidden" flag or not:
#include <QCoreApplication> #include <QDirListing> int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); if (app.arguments().size() != 2) return 1; QDirListing lst(app.arguments().last(), {".*"}, QDirListing::IteratorFlag::FilesOnly | QDirListing::IteratorFlag::Recursive /*| QDirListing::IteratorFlag::IncludeHidden*/); for (const auto &entry : lst) qDebug() << entry.fileName(); }
Note that it's not trivial to filter the unwanted files later, as one would have to painstakingly check every directory component in the path, which completely defeats the purpose of using QDirListing in the first place.
Possible solution: Make this aspect of IteratorFlags::IncludeHidden as specified in the docs configurable: "When combined with Recursive, the iteration will recurse into hidden sub-directories as well."
(Side note: I also wonder whether a name filter ".*" should find such files always even without IteratorFlags::IncludeHidden, given that the "hidden" property is entirely determined by the leading dot and I explicitly asked for these files.)
| For Gerrit Dashboard: QTBUG-141232 | ||||||
|---|---|---|---|---|---|---|
| # | Subject | Branch | Project | Status | CR | V |
| 685329,3 | QDirListing: add a new flag, NoRecurseHiddenDirs | dev | qt/qtbase | Status: NEW | +2 | 0 |