MFC코드 기반 디렉토리 생성과 삭제 코드 입니다.
디렉토리 삭제 참조: http://sanaigon.tistory.com/120
//
// 디렉토리 생성
// 디렉토리 생성 성공: TRUE, 실패: FALSE 반환
// 함수 사용예: CreateDir(_T("C:\\dir_name\\"));
//
BOOL CreateDir(CString dir)
{
CFileFind file;
CString strFile = _T("*.*");
BOOL bResult = file.FindFile(dir + strFile);
if(!bResult)
{
bResult = CreateDirectory(dir, NULL);
}
return bResult;
}
//
// 디렉토리 삭제
// 디렉토리내에 존재하는 하위 폴더 및 모든 파일 삭제
// 함수 사용예: DeleteDir(_T("C:\\dir_name\\*.*"));
//
BOOL DeleteDir(CString dir)
{
if(dir == _T(""))
{
return FALSE;
}
BOOL bRval = FALSE;
int nRval = 0;
CString szNextDirPath = _T("");
CString szRoot = _T("");
CFileFind find;
// Directory가 존재 하는지 확인 검사
bRval = find.FindFile(dir);
if(bRval == FALSE)
{
return bRval;
}
while(bRval)
{
bRval = find.FindNextFile();
// . or .. 인 경우 무시한다.
if(find.IsDots() == TRUE)
{
continue;
}
// Directory 일 경우
if(find.IsDirectory())
{
szNextDirPath.Format(_T("%s\\*.*"), find.GetFilePath());
// Recursion function 호출
DeleteDir(szNextDirPath);
}
// file일 경우
else
{
//파일 삭제
::DeleteFile(find.GetFilePath());
}
}
szRoot = find.GetRoot();
find.Close();
Sleep(1);
bRval = RemoveDirectory(szRoot);
return bRval;
}
'개발이야기 > MFC' 카테고리의 다른 글
| MFC 버튼 마우스 커서 변경 (0) | 2012.06.21 |
|---|---|
| fopen_s 파일읽기와 저장 (0) | 2012.06.14 |
| 뮤텍스를 이용한 프로그램 중복실행 방지 (0) | 2012.05.18 |
| 일정 날짜 기준 로그파일 제거 (1) | 2012.05.17 |
| 로컬 IP주소 얻기 (0) | 2012.05.17 |