폴더 없을 때 폴더 생성 코드
//폴더 없을경우 폴더 작성
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;
}
'개발공부 > C++' 카테고리의 다른 글
[C++ MFC] 문자열 _T("")와 L"" (0) | 2024.12.26 |
---|---|
[C++ ] Systemtime : 시스템 시간 날짜 얻어오기 (0) | 2024.12.17 |
[C++ MFC] 출력 창에서 디버깅 내용 보기 (0) | 2024.12.04 |
[C++ MFC] CTime 클래스 시간 형식 예시 (0) | 2024.11.12 |
[C++ MFC] 다이얼로그 창 항상 앞으로 띄우기, 주기적으로 창 앞으로 띄우기 (0) | 2024.11.05 |