// 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();}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。