删除文件夹里的所有文件

  1. 获得可执行文件所在路径的文件夹
1 CString sText;
2  TCHAR szPath[MAX_PATH];
3  ZeroMemory(szPath, sizeof(TCHAR)*MAX_PATH);
4  GetModuleFileName(NULL, szPath, sizeof(TCHAR)*MAX_PATH);
5  LPTSTR pos01 = _tcsrchr(szPath, '\\');
6  if (pos01 != NULL)
7   *pos01 = '\0'; 
8  CString sFilePath;
9  sFilePath =  CString(szPath) +_T("\\Temp\\*.*");
View Code

 

      2. 查找文件并删除

 1 CFileFind fileFinder;
 2  BOOL bFile = fileFinder.FindFile(sFilePath);
 3  while(bFile)
 4  {
 5   bFile = fileFinder.FindNextFile();
 6   
 7   if(!fileFinder.IsDirectory() && !fileFinder.IsDots()) //当为文件时;
 8   {
 9    CString strFullName = fileFinder.GetFilePath();
10    DeleteFile(strFullName);
11   }
12  }
13  
14  fileFinder.Close();

 

posted @ 2015-02-10 18:32  风的哀伤  阅读(591)  评论(0)    收藏  举报