CString strDirectory;//项目文件所在目录
char cDataPath[MAX_PATH];//文件路径
GetModuleFileName( NULL, cDataPath, MAX_PATH );
strDirectory=cDataPath;//将字符数组赋值过去
int k=strDirectory.ReverseFind('\\');//从后面查找\字符
strDirectory=strDirectory.Left(strDirectory.GetLength()-k);//截断获得\前面的一段字符串,即为目录文件夹
下面删除该文件夹下所有后缀名为.tmp的文件:
system(strDirectory); //跳转到该路径
system("del *.tmp"); //删除该路径下所有.tmp
因为调用了dos命令,因此会出现dos窗口闪烁的情况,那么可采用下面的方法:
<pre name="code" class="cpp">fcloseall();
CString strFind,strFindResult;
strFind=strDirectory+"\*.tmp";
CFileFind ff;
BOOL res = ff.FindFile(strFind);
while(res)
{
strFindResult = ff.GetFileName();
<pre name="code" class="cpp"> remove(strFindResult );
res = ff.FindNextFile();}
ff.Close();