[C++] std::fileSystem 으로 디렉토리 존재 여부 확인.

빵욱·2025년 1월 8일

std::filesystem::exists 함수로 디렉토리 존재 여부를 확인할 수 있는데
파라미터 인자로 디렉토리 주소 스트링 데이터를 넣어주면 된다.

if (!std::filesystem::exists(wstrPathDir))
{
	if (!std::filesystem::create_directories(wstrPathDir))
	{
		return false;
	}
}

return true;

근데 특이점이 디렉토리 스트링 데이터 마지막에(예제 코드에선 wstrPathDir) '\'(윈도우에선 역슬래쉬)가 붙어 있으면 create_directories 동작 시 생성은 되지만 결과는 false로 된다.

profile
rove drink eat

0개의 댓글