根据文件路径获得其所在文件夹,并删除该文件夹下后缀名为.tmp的所有文件

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();
 
 
 
 

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值