// 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();
}
vs2008中遍历文件夹中的文件
最新推荐文章于 2023-03-12 15:39:32 发布