Searches for the specified pattern in the current directory and recursively in all subdirectories, whilst retaining the original file pattern
| 2550 | #include <windows.h> |
| 2551 | /// Searches for the specified pattern in the current directory and recursively in all subdirectories, whilst retaining the original file pattern |
| 2552 | BOOL LASreadOpener::add_file_name_recursive(const std::string& pattern, BOOL unique) { |
| 2553 | // Process the pattern itself first |
| 2554 | add_file_name(pattern.c_str(), unique); |
| 2555 | |
| 2556 | // Split the pattern into a directory and a suffix |
| 2557 | std::string p = pattern; |
| 2558 | size_t pos = p.find_last_of("\\/:"); |
| 2559 | std::string dir; |
| 2560 | std::string suffix; |
| 2561 | |
| 2562 | // If no slash use current directory |
| 2563 | if (pos == std::string::npos) { |
| 2564 | dir = "."; |
| 2565 | suffix = p; |
| 2566 | } else { |
| 2567 | dir = p.substr(0, pos); |
| 2568 | suffix = p.substr(pos + 1); |
| 2569 | } |
| 2570 | |
| 2571 | std::string search = dir + "\\*"; |
| 2572 | |
| 2573 | WIN32_FIND_DATA info; |
| 2574 | HANDLE h = FindFirstFile(search.c_str(), &info); |
| 2575 | if (h == INVALID_HANDLE_VALUE) return TRUE; |
| 2576 | |
| 2577 | do { |
| 2578 | if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 2579 | const char* name = info.cFileName; |
| 2580 | |
| 2581 | // Skip '.' and '..' |
| 2582 | if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) continue; |
| 2583 | |
| 2584 | std::string new_pattern = dir + "\\" + name + "\\" + suffix; |
| 2585 | |
| 2586 | // Process recursively |
| 2587 | add_file_name_recursive(new_pattern, unique); |
| 2588 | } |
| 2589 | |
| 2590 | } while (FindNextFile(h, &info)); |
| 2591 | |
| 2592 | FindClose(h); |
| 2593 | return TRUE; |
| 2594 | } |
| 2595 | |
| 2596 | BOOL LASreadOpener::add_file_name(const CHAR* file_name, BOOL unique) { |
| 2597 | BOOL r = FALSE; |