본문 바로가기

컴퓨터 과학 & 영상처리 관련/MFC

MFC 다이얼로그에서 폴더선택 후 내부 파일 접근


출처 : http://www.tipssoft.com/bulletin/board.php?bo_table=FAQ&wr_id=274




아래와 같이 해도 여러 폴더나, 폴더 내부를 재귀적으로 도는 것이 아님

함수포인터는 클래스함수포인터 쓸 때에 머리 아프고. 대충 돌아가게 짤라면 이렇게밖에 안되나.

아무튼 인터넷이 있어서 참 고맙다


클래스 함수포인터 : http://zeph.tistory.com/155






void CClass_Dlg::OnBnClickedManual()

{

    char m_init_path[MAX_PATH];

    char path[MAX_PATH] = {0,};

    

    BROWSEINFO bi;

    bi.hwndOwner = this->m_hWnd;

    bi.pidlRoot = NULL;

 

    // 선택할 디렉토리가 저장될 버퍼

    bi.pszDisplayName = NULL;

 

    // 출력될 문자열

    bi.lpszTitle = "폴더를 선택하세요!";

 

    // 디렉토리 선택 옵션

    bi.ulFlags = BIF_RETURNONLYFSDIRS;

 

    //// 이벤트에 대한 사용자정의 함수

    //bi.lpfn = BrowseCallbackProc;

 

    // 사용자정의 함수에 넘겨질 인자로 사용자가 설정하고자 하는 경로를 설정한다.

    bi.lParam = (LPARAM)m_init_path;



LPITEMIDLIST  pidl = SHBrowseForFolder(&bi);

// 경로를 얻어온다.

SHGetPathFromIDList(pidl, path);


// 사용자가 폴더지정을 한 후 확인(OK)를 눌렀다면 해당 폴더의 경로에 대한 문자열이

// 존재하므로 end_pos 의 값은 0 이 아니다. 취소를 눌렀다면 0 의 값을 가진다.

int end_pos = strlen(path);


if(end_pos){

long h_file;

char search_Path[100];

FILE_SEARCH file_search;

sprintf_s(search_Path, "%s/*.*", path); 

if((h_file = _findfirst(search_Path, &file_search)) == -1L) { 

printf( "No files in current directory!\n" ); 


} else 

{

do 

{  

sprintf(search_Path, "%s\\%s",path, file_search.name);  

/////////////파일 존재하면 함수 수행//////////////////////////

if(isFileExists(search_Path)) 

{

//search_Path가 파일명이네...

}   

/////////////파일 존재하면 함수 수행//////////////////////////

} while (_findnext(h_file, &file_search) == 0);

_findclose(h_file); 

}

    }


AfxMessageBox("func over");


}