vc++遍历文件
来源:互联网 发布:vb sleep 编辑:程序博客网 时间:2024/05/17 04:18
应包含的头文件:
#include <io.h>
1. 遍历文件夹下的文件(不包括子文件夹)例如查找全部jpg图片,fileName为 [folderPath]\\*.jpg
int fileCount=0;_finddata_t fileInfo;long handle = _findfirst(fileName, &fileInfo);if (handle == -1L){cerr << "failed to transfer files" << endl;return false;}do {fileCount++;}while (_findnext(handle, &fileInfo) == 0);cout<<"================================================"<<endl;cout<<"there are "<<fileCount<<" images in "<<fpath<<endl;cout<<"================================================"<<endl;
2. 遍历包括子文件夹的文件,fileType为类似于“.jpg”,如果要查找全部文件则fileType为空或者“*”
void findFileInFolder(string folderPath,string fileType){_finddata_t FileInfo;string strfind = folderPath + "\\*" + fileType;long Handle = _findfirst(strfind.c_str(), &FileInfo);if (Handle == -1L){cerr << "can not match the folder path" << endl;exit(-1);}do{//判断是否为子目录if (FileInfo.attrib & _A_SUBDIR) {//忽略当前和父文件夹("." 和 "..")if( (strcmp(FileInfo.name,".") != 0 ) &&(strcmp(FileInfo.name,"..") != 0)) {string newPath = folderPath + "\\" + FileInfo.name;findFileInFolder(newPath,fileType);}}else {cout << folderPath << "\\" << FileInfo.name << "\n";}}while (_findnext(Handle, &FileInfo) == 0);_findclose(Handle);}
- VC遍历INI文件
- VC遍历INI文件
- vc++遍历文件
- VC 遍历指定目录下的文件
- VC下遍历文件夹中的所有文件
- VC++遍历文件夹中的所有文件
- 遍历目录下所有文件(VC)
- VC下遍历文件夹查找文件
- vc 遍历文件夹,删除文件及文件夹!
- VC下遍历文件夹查找文件
- VC使用tinyxml 遍历xml文件
- vc遍历文件夹下的所有文件
- VC枚举(遍历)文件夹里面的文件
- VC++根据路径遍历所有文件
- 用VC遍历文件夹中的所有文件及文件夹
- VC++中如何遍历整个目录树查找文件
- VC++中如何遍历整个目录树查找文件
- 在VC环境下怎样遍历文件夹中的文件
- mysql错误:Error NO. 1130?如何解决?
- 《UNIX环境高级编程》笔记--目录操作
- 导库的问题与感想(随便看)
- Qt源码编译完成后,执行中出现undefined symbol: _ZN16QCoreApplicationC1ERiPPci错误解决方案
- ..\OBJ\ucgui_ucos.axf: Error: L6218E: Undefined symbol ff_convert (referred from ff.o). ..\OBJ\ucgui
- vc++遍历文件
- Eclipse 换皮肤
- SQL Server 2008 R2 使用 PIVOT 错误
- linux内核api参考手册
- Windows 8.1 TTS API
- Android的PVPlayer介绍
- Oracle 10g应用优化
- NGUI系列教程一Spirit
- arduino----mpu6050