| 994 | } |
| 995 | |
| 996 | std::vector<common_file_info> fs_list(const std::string & path, bool include_directories) { |
| 997 | std::vector<common_file_info> files; |
| 998 | if (path.empty()) return files; |
| 999 | |
| 1000 | std::filesystem::path dir(path); |
| 1001 | if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir)) { |
| 1002 | return files; |
| 1003 | } |
| 1004 | |
| 1005 | for (const auto & entry : std::filesystem::directory_iterator(dir)) { |
| 1006 | try { |
| 1007 | // Only include regular files (skip directories) |
| 1008 | const auto & p = entry.path(); |
| 1009 | if (std::filesystem::is_regular_file(p)) { |
| 1010 | common_file_info info; |
| 1011 | info.path = p.string(); |
| 1012 | info.name = p.filename().string(); |
| 1013 | info.is_dir = false; |
| 1014 | try { |
| 1015 | info.size = static_cast<size_t>(std::filesystem::file_size(p)); |
| 1016 | } catch (const std::filesystem::filesystem_error &) { |
| 1017 | info.size = 0; |
| 1018 | } |
| 1019 | files.push_back(std::move(info)); |
| 1020 | } else if (include_directories && std::filesystem::is_directory(p)) { |
| 1021 | common_file_info info; |
| 1022 | info.path = p.string(); |
| 1023 | info.name = p.filename().string(); |
| 1024 | info.size = 0; // Directories have no size |
| 1025 | info.is_dir = true; |
| 1026 | files.push_back(std::move(info)); |
| 1027 | } |
| 1028 | } catch (const std::filesystem::filesystem_error &) { |
| 1029 | // skip entries we cannot inspect |
| 1030 | continue; |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | return files; |
| 1035 | } |
| 1036 | |
| 1037 | // |
| 1038 | // TTY utils |
no test coverage detected