遍历文件夹中指定文件

void CCISSQLDBDlg::FindMyFile(CString FilePath,CString FileFormat,CStringArray& arrFilePath,CStringArray& arrName)
{
 BOOL bFind, bFindSuffix;
 CFileFind tempFind, tempFind1; //定义文件查找类型变量
 _chdir(FilePath);
 bFind=tempFind.FindFile(_T("*.*"));//如果所在目录下有*.*文件返回1,如果没有就返回0
 while(bFind)                       //访问1进入循环  
 {                                 
  bFind = tempFind.FindNextFile(); //查找下一个文件
  if(tempFind.IsDirectory())      //如果tempFind是目录
  {
   if(!tempFind.IsDots())      //判断tempFind下面是否还有子目录
   {
    CString tempFindPath;  
    tempFindPath=tempFind.GetFilePath();  //查找文件所在的路径
    FindMyFile(tempFindPath,FileFormat,arrFilePath,arrName);//递归函数
   }
  }
 }
 _chdir(FilePath);
 bFindSuffix=tempFind1.FindFile(_T("*.*"));
 while(bFindSuffix)
 { 
  bFindSuffix = tempFind1.FindNextFile();
  CString strFilePath, strFileName;
  if ( !tempFind1.IsDirectory() && !tempFind1.IsDots() )
  {
   strFilePath = tempFind1.GetFilePath();
   strFileName = tempFind1.GetFileName();
   strFileName.MakeUpper();
   FileFormat.MakeUpper();
   if(strFileName.Right(3)== FileFormat&&strFileName.Left(1)!="~")//判断文件.右边3个字符等于指定的为扩展名并且文件前面无~
   {
    arrFilePath.Add(strFilePath); //将该文件的绝对路径保存到arrFilePath数组中
    arrName.Add(strFileName);     //将该文件的名字保存到arrName数组中
   }
  }
 }
 tempFind.Close();
 tempFind1.Close();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值