ファイルまたはディレクトリが存在するかどうかを確認します:C、C ++、Windows API、ブースト



Determine If Files Directories Exist



まず、ファイルが存在するかどうかを確認します

#ifdef WIN32 #include //C (Windows) access #else #include //C (Linux) access #endif #include //C++ fstream #ifdef WIN32 #include //Windows API FindFirstFile #include #pragma comment(lib, 'shlwapi.lib') //Windows API PathFileExists #endif #include //boost using namespace std int main() { char file_name[] = 'D://aa.txt' //C run in windows and linux if ( 0 == access(file_name, 0) ) cout<<'access(): file exist.'<

次に、ディレクトリが存在するかどうかを確認します



#ifdef WIN32 #include //C (Windows) access #else #include //C (Linux) access #endif #ifdef WIN32 #include //Windows API FindFirstFile #include #pragma comment(lib, 'shlwapi.lib') //Windows API PathFileExists #endif #include //boost using namespace std int main() { char file_name[] = 'D://b' //C run in windows and linux if ( 0 == access(file_name, 0) ) cout<<'access(): path exist.'<

第三に、比較するいくつかの方法
1.ファイルとディレクトリを正確に判断する

FindFirstFile()(Windows API、Windows)



ブースト(ブースト、WindowsおよびLinux)

2.ファイルボックスディレクトリの不正確な判断

access()(C、WindowsおよびLinux)



PathFileExists()(Windows API、Windows)

GetFileAttributes()(Windows API、Windows)

3.ファイルのみを判断できます

fstream(C ++ STL、WindowsおよびLinux)

CreateFile()(Windows API、Windows)
---------------------
OF:kanguolaikanguolaik
出典:CSDN
オリジナル:https://blog.csdn.net/guowenyan001/article/details/17259173
著作権表示:この記事はブロガーのオリジナル記事です。ブログ投稿リンクを添付してください。