打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
vs2008中遍历文件夹中的文件
// CrossValidationFace.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<iostream>#include <windows.h>#include <stdio.h>#include <string.h>using namespace std;#define LEN 1024// 深度优先递归遍历目录中所有的文件BOOL DirectoryList(LPCSTR Path){ WIN32_FIND_DATA FindData; HANDLE hError; int FileCount = 0; char FilePathName[LEN]; // 构造路径 char FullPathName[LEN]; strcpy_s(FilePathName, Path); strcat_s(FilePathName, "\\*.*"); hError = FindFirstFile(FilePathName, &FindData); if (hError == INVALID_HANDLE_VALUE) { printf("搜索失败!"); return 0; } while(::FindNextFile(hError, &FindData)) { // 过虑.和.. if (strcmp(FindData.cFileName, ".") == 0 || strcmp(FindData.cFileName, "..") == 0 )//是文件 { continue; } // 构造完整路径 wsprintf(FullPathName, "%s\\%s", Path,FindData.cFileName); FileCount++; // 输出本级的文件 printf("\n%d %s ", FileCount, FullPathName); if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)//是路径 { printf("<Dir>"); DirectoryList(FullPathName); } } return 0;}void main(){ DirectoryList("C:\\Users\\admin\\Desktop\\CroppedYale"); getchar();}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
递归遍历某一路径下的所有文件(for windows or linux)
C++删除文件夹代码
FindFirstFile的正确用法
两种方法使用VC遍历文件夹下所有文件和文件夹
VBA基础入门(42)Find查找到不存在的数据出错怎么办?
使用FindFirstFile,FindNextFile遍历一个文件夹
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服