#include <string>
      
      int main() {
        std::string filename = "C:\\MyDirectory\\MyFile.bat";
        const size_t last_slash_idx = filename.find_last_of("\\/");
        if (std::string::npos != last_slash_idx) {
          filename.erase(0, last_slash_idx + 1);
        }
        const size_t period_idx = filename.rfind('.');
        if (std::string::npos != period_idx) {
          filename.erase(period_idx);
        }
        return 0;
      }
      
      Cpp language logo

      Filename from path

      Codiga's C++ Recipes

      Get a file name from a Windows path

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.