分享

vs2008中遍历文件夹中的文件

 行走在理想边缘 2018-11-26
// 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(); }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多