MFC/C++只删除磁盘下的指定后缀名的文件

bool  DeleteTestFile(char Drv)
{
    bool bFound;
    BOOL result;
    CString strFname;
    
    //-- Delete All Data Files --
    TCHAR SearchDir[512];
    TCHAR strFile[512];

    sprintf( SearchDir, _T("%c:\\*.*"), Drv );

    // Find the first file in the directory.
    HANDLE hFind = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA ffd;

    bFound = false;
    hFind = FindFirstFile(SearchDir, &ffd);
    if (hFind != INVALID_HANDLE_VALUE)
      {
         do{
              if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 )
                {
                   strFname.Format( "%s", ffd.cFileName );
                   if ( strFname.Find(".h2w") != -1 )
                     {
                        sprintf  ( strFile, "%c:\\%s", Drv, ffd.cFileName );
                        result = DeleteFile( strFile );
                        bFound = ( result ) ? true : bFound;
                     }
                }
         }while( FindNextFile(hFind, &ffd) != 0 );
         FindClose(hFind);
      }

    return bFound;
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值