遍历文件夹下指定的文件类型

#include <vector>
#include <afxtempl.h>
#include <Shlwapi.h>
#define _VEC_FILE_ std::vector<std::pair<CString, CString>>  //保存文件路径和名称容器
/*
 *  函数:
 * GetSendFilePath(获取需要发送的文件)
 *  参数:
 * vecFilePath:装载需要发送的文件路径容器
 * strFileType:遍历文件类型(*.xml ,*.*,*.jpg等类型)
 *  返回值:
 * 返回需要发送文件的总数
 * ssdwujianhua 2017/06/06 
 */
size_t CThreadSanjifenfaReport::GetSendFilePath(_VEC_FILE_ &vecFilePath, CSting strFileType)
{
//遍历当前文件夹中的所有文件
CString strPath = m_sjffInfo.strSaveReportFilePath;
if ( !strPath.IsEmpty() )
{
CFileFind fileFinder;//类CFileFind执行本地文件查找  
CString strPicFile;
CString strFilePath;//保存文件路径  
CString strFileName;//保存文件名  
do  
{  
if (strPath.Right(1) == TEXT("\\"))  
{  
int nPos  = strPath.ReverseFind(TEXT('\\'));  
strPath = strPath.Left(nPos);  
}  
strPicFile.Format(TEXT("%s\\%s"),strPath,strFileType);
BOOL bWorking = fileFinder.FindFile(strPicFile);  
if ( !bWorking )
{
break;
}
while (bWorking)  
{     
bWorking = fileFinder.FindNextFile();  
if (fileFinder.IsDots())//IsDots判断是否为点,由CFileFind对象引用IsDots的意思是:这是一个目录并且不是这个目录本身或者上层目录  
{  
continue;  
}  
strFilePath = fileFinder.GetFilePath();//文件的完整路径  
strFileName = fileFinder.GetFileName();//文件的名字  
if (fileFinder.IsDirectory())//检查是否是文件夹,是返回true,不是返回false  
{     
//继续遍历目录  
continue;  
}  
else  
{     
int nPos = strFilePath.ReverseFind(TEXT('.'));  
CString strExt = strFilePath.Right(strFilePath.GetLength() - nPos - 1);  
if (strExt.CompareNoCase(strFileType)  == 0)  
{     
vecFilePath.push_back(std::pair<CString, CString>(strFilePath, strFileName));
}  
}  
}  
}while(fileFinder.FindNextFile());  
fileFinder.Close();
}
return vecFilePath.size();
}

 








  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值