| 5 | #include <util/system/defaults.h> |
| 6 | |
| 7 | void TFileEntitiesList::Fill(const TString& dirname, TStringBuf prefix, TStringBuf suffix, int depth, bool sort) { |
| 8 | TDirIterator::TOptions opts; |
| 9 | opts.SetMaxLevel(depth); |
| 10 | if (sort) { |
| 11 | opts.SetSortByName(); |
| 12 | } |
| 13 | |
| 14 | TDirIterator dir(dirname, opts); |
| 15 | Clear(); |
| 16 | |
| 17 | size_t dirNameLength = dirname.length(); |
| 18 | while (dirNameLength && (dirname[dirNameLength - 1] == '\\' || dirname[dirNameLength - 1] == '/')) { |
| 19 | --dirNameLength; |
| 20 | } |
| 21 | |
| 22 | for (auto file = dir.begin(); file != dir.end(); ++file) { |
| 23 | if (file->fts_pathlen == file->fts_namelen || file->fts_pathlen <= dirNameLength) { |
| 24 | continue; |
| 25 | } |
| 26 | |
| 27 | TStringBuf filename = file->fts_path + dirNameLength + 1; |
| 28 | |
| 29 | if (filename.empty() || !filename.StartsWith(prefix) || !filename.EndsWith(suffix)) { |
| 30 | continue; |
| 31 | } |
| 32 | |
| 33 | if (((Mask & EM_FILES) && file->fts_info == FTS_F) || ((Mask & EM_DIRS) && file->fts_info == FTS_D) || ((Mask & EM_SLINKS) && file->fts_info == FTS_SL)) { |
| 34 | ++FileNamesSize; |
| 35 | FileNames.Append(filename.data(), filename.size() + 1); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | Restart(); |
| 40 | } |