Skip to content

Instantly share code, notes, and snippets.

@DJmong
Created August 7, 2023 01:40
Show Gist options
  • Select an option

  • Save DJmong/3366fe2c55dfb33087b043825d5fa590 to your computer and use it in GitHub Desktop.

Select an option

Save DJmong/3366fe2c55dfb33087b043825d5fa590 to your computer and use it in GitHub Desktop.
file_exist check on windows11, C++17
#include <iostream>
#include <filesystem>
// *** OS : Windows
// *** Compiler : C++17
int directory_exist()
{
std::string dir = "C:\\test";
namespace fs = std::filesystem;
if (!fs::exists(dir))
{
std::cout << "Directory Not Exist!\n";
return 1;
}
std::cout << "Directory Exist!\n";
return 0;
}
int file_exist()
{
std::string file = "C:\\test\\test.txt";
namespace fs = std::filesystem;
if (!fs::exists(file))
{
std::cout << "File Not Exist!\n";
return 1;
}
std::cout << "File Exist!\n";
return 0;
}
int main(int argc, char** argv)
{
directory_exist();
file_exist();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment