돌아다니는 코드 개량해서 올림
#include <iostream>
#include <io.h>
#include <vector>
#include <tchar.h>
#include <string>
using namespace std;
using std::string;
using std::wstring;
#ifdef UNICODE
typedef wstring tstring;
#else
typedef string tstring;
#endif
// Check windows
#if _WIN32 || _WIN64
#if _WIN64
#define ENVIRONMENT64
#else
#define ENVIRONMENT32
#endif
#endif
// Check GCC
#if __GNUC__
#if __x86_64__ || __ppc64__
#define ENVIRONMENT64
#else
#define ENVIRONMENT32
#endif
#endif
#if defined(UNICODE) || defined(_UNICODE)
#define tcout std::wcout
#else
#define tcout std::cout
#endif
#ifdef ENVIRONMENT32
#define T_FIND_DATA _tfinddata_t
#define T_FIND_FIRST _tfindfirst
#define T_FIND_NEXT _tfindnext
#endif
#ifdef ENVIRONMENT64
#define T_FIND_DATA _tfinddata64_t
#define T_FIND_FIRST _tfindfirst64
#define T_FIND_NEXT _tfindnext64
#endif
vector<tstring> GetFilesInDirectory(const tstring& _absolutePath, const tstring& _filter)
{
tstring searching = _absolutePath + _filter;
vector<tstring> return_;
T_FIND_DATA fd;
const auto handle = T_FIND_FIRST(searching.c_str(), &fd); //현재 폴더 내 모든 파일을 찾는다.
if (handle == -1)
return return_;
auto result = 0;
do
{
if (fd.attrib & _A_SUBDIR) { // 디렉토리면
tstring dirName = fd.name;
if (_T(".") != dirName && _T("..") != dirName) {
tstring subPath = _absolutePath + dirName + _T("\\");
vector<tstring> vec = GetFilesInDirectory(subPath, _filter);
for (int i = 0; i < vec.size(); ++i)
return_.push_back(vec[i]);
}
}
else { // 파일이면
tstring fileName = fd.name;
return_.push_back(fileName);
}
result = T_FIND_NEXT(handle, &fd);
} while (result != -1);
_findclose(handle);
return return_;
}
int main() {
// 절대경로
tstring path = _T("N:\\Project\\DirectX2019Game\\DirectX11Game\\OutputFile\\bin\\content\\texture\\");
// 필터
tstring filter = _T("*.*");
vector<tstring> veclist = GetFilesInDirectory(path, filter);
for (int i = 0; i < veclist.size(); ++i) {
tcout << veclist[i].c_str() << _T("\n");
}
return 0;
}
'언어 > C++' 카테고리의 다른 글
C++ 캐스팅을 이용한 구조체와 배열 호환 (0) | 2021.08.03 |
---|---|
C++ 디폴트 할당자와 비교자가 사용될 때 컨테이너에 저장되는 항목이 가져야 할 상세 요건 (0) | 2021.02.25 |
C++ 캐스팅 방법 정리 표 (0) | 2021.02.10 |
C++ 무엇이 있는지 한 번이라도 확인은 해봐야 하는 STL의 알고리즘 모음 (0) | 2021.02.04 |
C++11 에서 소스코드에 벤더 종속적인 정보나 옵션 사항을 지정해야 할 경우. (0) | 2021.01.27 |