머리말
프로젝트 개발에서 특정 폴더의 일부 리소스 파일을 탐색해야 하는 경우가 종종 있습니다. 바퀴를 재발 명하지 않기 위해 여기에 기록했습니다.
구현 아이디어
1. 폴더 이름 지정
2. 파일 핸들 얻기 3. 합계
필터링 (상위 및 현재 디렉터리) 4. 구조의 속성을 가져와 폴더, 파일 등 식별.
..
__finddata64_t
attrib
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Macros
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// File attribute constants for the _findfirst() family of functions
#define _A_NORMAL 0x00 // Normal file - No read/write restrictions
#define _A_RDONLY 0x01 // Read only file
#define _A_HIDDEN 0x02 // Hidden file
#define _A_SYSTEM 0x04 // System file
#define _A_SUBDIR 0x10 // Subdirectory
#define _A_ARCH 0x20 // Archive file
소스 코드
개발 환경이 32비트일 경우 , , __finddata64_t
3 개를 , , 로 변경 해야 합니다 ._findfirst64
_findnext64
_finddata32_t
_findfirst
_findnext
std::string path = "./tset/"+ '*';
__finddata64_t fileInfo;
intptr_t hFile = _findfirst64(path.c_str(), &fileInfo);
if(-1 != hFile)
{
do
{
if(_A_SUBDIR == fileInfo.attrib && 0 != strcmp(fileInfo.name, ".") && 0 != strcmp(fileInfo.name, ".."))
{
qDebug() << QString::fromStdString(fileInfo.name);
}
}while(0 == _findnext64(hFile, &fileInfo));
}