Advertisement
Ameisen

Untitled

Jan 15th, 2021
168
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdio>
  2. #include <string>
  3. #include <filesystem>
  4.  
  5. namespace fs = std::filesystem;
  6.  
  7. namespace os {
  8.     const char* path_separator() { return "\\"; }
  9. }
  10.  
  11. const char java_home[] = "B:\\java\\mc\\builds\\windows-x86_64-mc-release-skylake-x";
  12.  
  13. int main() {
  14.     auto fprintln = [](const std::string& str) {
  15.         printf("%s\n", str.c_str());
  16.     };
  17.  
  18.     fs::path overrideRoot = java_home;
  19.     fprintln(overrideRoot.string());
  20.     overrideRoot /= "override";
  21.     fprintln(overrideRoot.string());
  22.     fs::directory_entry overrideDir{ overrideRoot };
  23.     if (overrideDir.is_directory()) {
  24.         using iterator = fs::recursive_directory_iterator;
  25.         for (iterator iter{ overrideDir }; iter != iterator(); ++iter) {
  26.             // works fine
  27.             const auto & override = *iter;
  28.             fprintln(override.path().string());
  29.             if (override.exists() && !override.is_directory()) {
  30.                 std::string overridePath = override.path().string();
  31.                 fprintln(overridePath);
  32.             }
  33.         }
  34.         for (const auto & override : iterator{ overrideDir }) {
  35.             // works fine
  36.             fprintln(override.path().string());
  37.             if (override.exists() && !override.is_directory()) {
  38.                 std::string overridePath = override.path().string();
  39.                 fprintln(overridePath);
  40.             }
  41.         }
  42.         for (const auto & override : iterator( overrideDir )) {
  43.             // doesn't enter
  44.             if (override.exists() && !override.is_directory()) {
  45.                 std::string overridePath = override.path().string();
  46.                 puts(overridePath.c_str());
  47.             }
  48.         }
  49.     }
  50. }
  51.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement