| 306 | } |
| 307 | |
| 308 | StrArr *ListFileTree(const char *path, int mode) { |
| 309 | StrArr *result = new StrArr(); |
| 310 | FileInfo info; |
| 311 | if (FileStat(info, path, true)) { |
| 312 | if (info.is_dir) { |
| 313 | Str *dir = new Str(path); |
| 314 | if (!dir->ends_with(PathSeparator)) |
| 315 | dir->add(PathSeparator); |
| 316 | Int prefixlen = dir->len(); |
| 317 | result->add(dir); |
| 318 | WalkDir(result, dir->c_str(), mode); |
| 319 | if (mode & ListFilesRelative) { |
| 320 | for (Int i = 0; i < result->len(); i++) { |
| 321 | result->at(i)->remove(0, prefixlen); |
| 322 | } |
| 323 | } |
| 324 | } else { |
| 325 | if ((mode & ListFilesRelative) == 0) |
| 326 | result->add(S(path)); |
| 327 | } |
| 328 | } |
| 329 | return result; |
| 330 | } |
| 331 | |
| 332 | StrArr *ListFileTree(Str *path, int mode) { |
| 333 | return ListFileTree(path->c_str(), mode); |