现在的位置: 首页 > 综合 > 正文

检查给定目录是否存在,如果不存在则创建该目录

2013年08月26日 ⁄ 综合 ⁄ 共 1326字 ⁄ 字号 评论关闭

//=========================================================================//
//    功  能:获取当前应用程序的路径目录                                   //
//    参  数:无                                                           //
//    返回值:当前应用程序的路径目录                                       //
//    备  注:无                                                           //
//=========================================================================//
CString GetCurrentPath()
{
 TCHAR exeFullPath[MAX_PATH]; // MAX_PATH在API中定义了吧,好象是
 GetModuleFileName(NULL,exeFullPath,MAX_PATH);
 CString sPath;
 sPath=exeFullPath;
 int nPos;
 nPos=sPath.ReverseFind ('//');
 sPath=sPath.Left (nPos+1);
 return sPath;
}

//=========================================================================//
//    功  能:检查给定目录是否存在,如果不存在则创建该目录                 //
//    参  数:sDirectory,给定路径                                         //
//    返回值:无                                                           //
//    备  注:无                                                           //
//=========================================================================//
void CheckDirectory(CString sDirectory)
{
 //检查目录是否存在
 WIN32_FIND_DATA fd;
     HANDLE hFind = FindFirstFile(sDirectory, &fd);
     if (!((hFind != INVALID_HANDLE_VALUE) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)))
     {
  ::CreateDirectory(sDirectory,NULL);
     }
     FindClose(hFind);

抱歉!评论已关闭.