[Visual C++] 디렉토리&파일 관련 함수

1. 디렉토리 안의 파일 목록 얻기(하위 디렉토리 가능)
std::vector<std::string> files = GetFileList_R(
    "C:/Users/hotspring/Downloads/LP-Bind drop out"
  , "*.jpg;*.bmp");
std::vector<std::string> GetFileList(std::string dir_path, std::string ext,bool recursive=false) {
	std::vector<std::string> paths;	//return value
	if (dir_path.back() != '/' && dir_path.back() != '\\') {
		dir_path.push_back('/');
	}
	std::string str_exp = dir_path + "*.*";
	std::vector<std::string> allow_ext;
	std::string::size_type offset = 0;
	while (offset<ext.length()){
		std::string str = ext.substr(offset, ext.find(';', offset) - offset);
		std::transform(str.begin(), str.end(), str.begin(), toupper);
		offset += str.length() + 1;
		allow_ext.push_back(str.substr(2,str.length()));
	}
	WIN32_FIND_DATAA fd;
	HANDLE hFind = ::FindFirstFileA(str_exp.c_str(), &fd);
	if (hFind == nullptr) {
		return paths;
	}
	do {
		std::string path = fd.cFileName;
		if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){	//if this is file
			std::string path_ext = path.substr(path.find_last_of('.') + 1, path.length());	//파일의 확장자 추출
			std::transform(path_ext.begin(), path_ext.end(), path_ext.begin(), toupper);
			int i = -1;
			while (++i < allow_ext.size() && allow_ext[i] != path_ext);	
			if (i<allow_ext.size()){	//allow_ext에 포함되어있으면
				paths.push_back(dir_path + path);
			}
		}
		else if (recursive==true && path != "." && path != ".."){
			std::vector<std::string> temps = GetFileList(dir_path + path, ext);
			for (auto&temp : temps){
				paths.push_back(temp);
			}
		}
	} while (::FindNextFileA(hFind, &fd));
	::FindClose(hFind);
	return paths;	//RVO
}

http://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c

_finddata_t 자료형 x64에서 안됨
http://xiasonic.tistory.com/143

https://msdn.microsoft.com/ko-kr/library/windows/desktop/bb773584(v=vs.85).aspx

2. 파일 존재 여부
#include <Shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")
BOOL PathFileExists(_In_ LPCTSTR pszPath);
3. 현재 디렉토리 경로
TCHAR programpath[_MAX_PATH];
// 실행파일 경로
GetModuleFileName( NULL, programpath, _MAX_PATH);
// 현재 폴더 경로
GetCurrentDirectory( _MAX_PATH, programpath);
POSIX function
#include <direct.h>
char *_getcwd(   
   char *buffer,  
   int maxlen   
);  

https://msdn.microsoft.com/ko-kr/library/sf98bd4y.aspx

4.상대경로->절대경로
_fullpath