Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- tcp
- c++
- Callback
- 책
- GO 언어
- File
- Python
- 리뷰
- JavaScript
- range
- Linux
- install
- Close
- 영화
- C
- Sync
- mutex
- windows
- package
- Golang
- channel
- go
- bitcoin
- FOR
- json
- window
- http
- API
- write
- go언어
Archives
- Today
- Total
Code Habit
Directory 생성, 삭제 본문
MFC 환경에서 Directory를 생성 및 삭제하는 예제이다.
- Directory 생성
BOOL MakeDir()
{
USES_CONVERSION;
BOOL bResult = FALSE;
do
{
if( -1 != access("c:\\mydir", 0) ) {
bResult = TRUE;
break;
}
if( !CreateDirectory( L"c:\\mydir", NULL) ) {
break;
}
bResult = TRUE;
}while(false);
return bResult;
}
|
access() 함수로 특정 디렉터리로가 존재하는 지 체크하고 없으면 CreateDriectory() 함수를 이용하여 디렉터리를 생성한다.
- Directory 삭제 ( 안에 있는 파일까지 다 지운다 )
BOOL DeleteDir()
{
TCHAR szPath[MAX_PATH] = {0, };
_stprintf_s( szPath, MAX_PATH, L"%s\\*.*", L"c:\\mydir" );
BOOL bResult = FALSE;
do
{
CFindFile finder;
BOOL bExist = finder.FindFile( szPath );
while( bExist )
{
bExist = finder.FindNextFile();
if( TRUE == finder.IsDots() ) {
continue;
} else if ( TRUE == finder.IsDirectory() ) {
RemoveDirectory( finder.GetFilePath() );
continue;
}
DeleteFile( finder.GetFilePath() );
}
finder.Close();
RemoveDirectory( L"c:\\mydir" );
bResult = TRUE;
} while( false );
return bResult;
}
|
CFindFile를 이용하여 디렉터리(\mydir) 안의 파일(&디렉터리)들을 순차적으로 검색&삭제하고 마지막 상위 디렉터리(\mydir)를 지운다.