Created
August 7, 2023 01:40
-
-
Save DJmong/3366fe2c55dfb33087b043825d5fa590 to your computer and use it in GitHub Desktop.
file_exist check on windows11, C++17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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