Total size of every regular file under dir (recursive). Best-effort: I/O errors stop the walk and return what was summed so far.
| 48 | |
| 49 | // Total size of every regular file under dir (recursive). Best-effort: I/O errors |
| 50 | // stop the walk and return what was summed so far. |
| 51 | int64_t DirSizeBytes(const std::filesystem::path& dir) |
| 52 | { |
| 53 | std::error_code ec; |
| 54 | int64_t total = 0; |
| 55 | std::filesystem::recursive_directory_iterator it(dir, ec), end; |
| 56 | for (; it != end; it.increment(ec)) |
| 57 | { |
| 58 | if (ec) |
| 59 | break; |
| 60 | std::error_code fec; |
| 61 | if (it->is_regular_file(fec)) |
| 62 | total += static_cast<int64_t>(it->file_size(fec)); |
| 63 | } |
| 64 | return total; |
| 65 | } |
| 66 | |
| 67 | // Display name: the mod.json "name" when present, else the folder name with a |