NX二次开发-检查文件是否存在

NX二次开发-检查文件是否存在

  • UF函数
 1 bool CheckFileExists(string filename)
 2 {
 3     if (filename.empty())
 4     {
 5         return false;
 6     }
 7 
 8     int status = 1;
 9     UF_CFI_ask_file_exist(filename.c_str(), &status);
10 
11     return (0 == status);
12 }
  • ifstream
 1 bool CheckFileExist(const std::string& fileName)
 2 {
 3   if (fileName.empty())
 4   {
 5    return false;
 6   }
 7 
 8   std::ifstream ifs(fileName.c_str(), std::ios_base::in);
 9 
10   if (ifs.is_open())
11    {
12       ifs.close();
13       return true;
14    }
15   else
16   {
17     return false;
18   }
19 }
原文地址:https://www.cnblogs.com/xiang-L/p/14372910.html