经常碰到朋友,尤其是初学者对指定文件夹下指定类型文件的读取很困惑,这里,我把自己经常用的程序贴出来,供初学者学些;
#include "stdafx.h"
#include "windows.h"
#include <vector>
#include <string>
#include "iostream"
using namespace std;
typedef std::vector<std::string> file_lists;
static int str_compare(const void *arg1, const void *arg2)
{
return strcmp((*(std::string*)arg1).c_str(), (*(std::string*)arg2).c_str());//比较字符串arg1 and arg2
}
file_lists ScanDirectory(const std::string &path, const std::string &extension)
{
WIN32_FIND_DATA wfd;//WIN32_FIND_DATA:Contains information about the file that is found by the
//FindFirstFile, FindFirstFileEx, or FindNextFile function
HANDLE hHandle;
string searchPath, searchFile;
file_lists vFilenames;