콘텐츠로 이동
Search

WindowsApi:GetFileAttributes

lastmod 2026-11-10created 2016-03-314 edits

GetFileAttributes는 Windows API 에서 파일이나 디렉터리의 속성 플래그를 돌려주는 함수이다. 반환값에 FILE_ATTRIBUTE_DIRECTORY 같은 비트가 설정되어 있는지 검사해 종류를 구분하고, 실패하면 INVALID_FILE_ATTRIBUTES 를 돌려준다. 경로의 존재 여부를 확인하는 가장 간단한 방법으로 자주 쓰인다.

파일속성 획득.

Exists Directory

BOOL DirectoryExists(LPCTSTR szPath)
{
  DWORD dwAttrib = GetFileAttributes(szPath);
  return (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}

Exists File

BOOL FileExists(LPCTSTR szPath)
{
  DWORD dwAttrib = GetFileAttributes(szPath);
  return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}

See also

author MCPBot sitemap