| 217 | } |
| 218 | |
| 219 | FilePathVec FilePath::getSubDirectories() const |
| 220 | { |
| 221 | if (!isDirectory()) |
| 222 | { |
| 223 | return FilePathVec(); |
| 224 | } |
| 225 | |
| 226 | FilePathVec dirs{ *this }; |
| 227 | |
| 228 | #if defined(_WIN32) |
| 229 | WIN32_FIND_DATAA fd; |
| 230 | string wildcard = "*"; |
| 231 | HANDLE hFind = FindFirstFileA((*this / wildcard).asString().c_str(), &fd); |
| 232 | if (hFind != INVALID_HANDLE_VALUE) |
| 233 | { |
| 234 | do |
| 235 | { |
| 236 | string path = fd.cFileName; |
| 237 | if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (path != "." && path != "..")) |
| 238 | { |
| 239 | FilePath newDir = *this / path; |
| 240 | FilePathVec newDirs = newDir.getSubDirectories(); |
| 241 | dirs.insert(dirs.end(), newDirs.begin(), newDirs.end()); |
| 242 | } |
| 243 | } while (FindNextFileA(hFind, &fd)); |
| 244 | FindClose(hFind); |
| 245 | } |
| 246 | #else |
| 247 | DIR* dir = opendir(asString().c_str()); |
| 248 | if (dir) |
| 249 | { |
| 250 | while (struct dirent* entry = readdir(dir)) |
| 251 | { |
| 252 | string path = entry->d_name; |
| 253 | if (path == "." || path == "..") |
| 254 | { |
| 255 | continue; |
| 256 | } |
| 257 | |
| 258 | auto d_type = entry->d_type; |
| 259 | FilePath newDir = *this / path; |
| 260 | |
| 261 | if (d_type == DT_UNKNOWN) |
| 262 | { |
| 263 | if (newDir.isDirectory()) |
| 264 | { |
| 265 | d_type = DT_DIR; |
| 266 | } |
| 267 | } |
| 268 | if (d_type == DT_DIR) |
| 269 | { |
| 270 | FilePathVec newDirs = newDir.getSubDirectories(); |
| 271 | dirs.insert(dirs.end(), newDirs.begin(), newDirs.end()); |
| 272 | } |
| 273 | } |
| 274 | closedir(dir); |
| 275 | } |
| 276 | #endif |
no test coverage detected