BLOG main image
전체 (276)
[Computer] (42)
[Programming] (62)
[DBMS] (26)
[Operating System] (21)
[Study English] (8)
[For money] (28)
[Interest] (89)
«   2009/11   »
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
29 30          
77917 Visitors up to today!
Today 14 hit, Yesterday 95 hit
'파일검색'에 해당되는 글 1건
[폭주기관차, 2007/03/10 20:15, [Programming]/Visual C++ API/MFC]
CFileFind란 Class를 사용하면 된다.

CFileFind cFileFinder;
BOOL bResult;

// path를 찾음 성공시 TRUE, 실패시 FALSE
bResult = cFileFinder.FindFile( path );
// 그 다음 같은 이름의 파일 혹은 디렉토리있으면 TRUE, 없으면 FALSE
bResult = cFileFinder.FindNextFile();

if( cFileFinder.IsDirectory() == TRUE )
 MessageBox( "디렉토리 존재함" );

FindNextFile을 하지 않고 IsDirectory() 함수를 호출하면 에러가 떠버린다.

아래와 같은 와일드 카드도 사용할 수 있다.

// C:\\*.*가 있으면 TRUE, C:\의 어떤 파일이라도 있으면 TRUE
bResult = cFileFinder.FindFile( "C:\\*.*" );
// 바로 GetFileName하면 NULL에러 발생 아직 파일을 찾은 것은 아님
bResult = cFileFinder.FindNextFile();
MessageBox( cFileFinder.GetFileName() );


첫 번째 파일 이름이 나옴
그 다음은 FindNextFile()함수를 호출하여 리턴값이 0이 나올때까지 돌리면 된다.
MSDN예제엔 아래와 같이 쓰도록 되어있다.

bResult = cFileFinder.FindFile( "C:\\*.*" )

while( bResult )
{
 bResult = cFileFinder.FindNextFile();

 // . 이나 ..이면 다시 돌림
 if( cFileFinder.IsDot() ) continue;

 MessageBox( cFileFinder.GetFileName() );
}


참고 : MSDN, 데브피아 여러 자료
Trackback Address :: http://kongmks.cafe24.com/trackback/175
Name
Password
Homepage
Secret
*1