소연의_개발일지

 

 

폴더 없을 때 폴더 생성 코드

	//폴더 없을경우 폴더 작성
	if (!PathIsDirectory(strFolderPath)) { // 경로 존재 여부 확인
		if (!CreateDirectory(strFolderPath, NULL)) {
			DWORD dwError = GetLastError();
			// 여기에 dwError를 로그로 남김 or 메세지박스로 남김
		}
	}

 

 

중간 폴더도 생성하는 재귀 함수

bool CreateDirectories(const CString& path) {
    CString currentPath = L"";
    int start = 0;

    while ((start = path.Find(L'\\', start + 1)) != -1) {
        currentPath = path.Left(start);
        if (!PathIsDirectory(currentPath)) {
            if (!CreateDirectory(currentPath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
                return false;
            }
        }
    }

    if (!PathIsDirectory(path)) {
        return CreateDirectory(path, NULL) || GetLastError() == ERROR_ALREADY_EXISTS;
    }
    return true;
}

 

profile

소연의_개발일지

@ssoyxon

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!