/*
GetFiles 함수
해당 경로의 파일 리스트를 가져온다.
bAllDirectories = true 일경우 하위폴더의 파일 리스트도 모두 가져온다.
*/
#include <windows.h>
#include <string>
#include <iostream>
#include <vector>
using namespace std;
void GetFiles(vector<string> &vList, string sPath, bool bAllDirectories);
int main()
{
vector<string> vec;
GetFiles(vec,"C:\\Users",true);
for (auto s:vec)
{
cout << s << endl;
}
return 0;
}
void GetFiles(vector<string> &vList, string sPath, bool bAllDirectories)
{
string sTmp = sPath + string("\\*.*");
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(sTmp.c_str(), &fd);
if (INVALID_HANDLE_VALUE != hFind)
{
do
{
if ( fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
if (bAllDirectories)
{
if (fd.cFileName[0] != '.')
{
sTmp =
sPath +
string("\\") +
string(fd.cFileName);
GetFiles(vList, sTmp, bAllDirectories);
}
}
}
else
{
sTmp =
sPath +
string("\\") +
string(fd.cFileName);
vList.push_back(sTmp);
}
} while(FindNextFile(hFind, &fd));
FindClose(hFind);
}
}
'Test Code > C++' 카테고리의 다른 글
[STL] template vector<int>, vector<string> 구분없이 사용하기 (0) | 2013.12.27 |
---|---|
[C++] 파일 한줄씩 읽기 두가지 함수 (0) | 2013.12.27 |
[WinApi] GetCurrentDirectory 현재 경로 가져오기 (0) | 2013.12.27 |
[WinApi] Ini 파일 읽고 쓰기 (0) | 2013.12.27 |
[C++]배열 사이즈 구하기 (0) | 2013.12.27 |