// testGetAllFiles.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<Windows.h>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
vector<string> GetAllFiles(string directory,string filter);
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> files=GetAllFiles("F://My Documents//","*.*");
for (vector<string>::iterator it =files.begin();it!=files.end();it++)
{
cout<<(*it).c_str()<<"/t";
}
return 0;
}
vector<string> GetAllFiles(string directory,string filter)
{
HANDLE SerachHandle;
WIN32_FIND_DATA FindData;
string pathName=directory+filter;
vector<string> fileList;
SerachHandle=FindFirstFile(pathName.c_str(),&FindData);
if (INVALID_HANDLE_VALUE==SerachHandle)
{
return fileList;
}
do
{
fileList.push_back(string(FindData.cFileName));
} while (FindNextFile(SerachHandle,&FindData));
FindClose(SerachHandle);
return fileList;
}
获取目录下所有的文件(非递归)
最新推荐文章于 2022-09-16 14:39:47 发布