목표 : MFC Dialog 환경에서 폴더를 선택하면 해당 폴더내 파일명 앞에 년원일 이 붙도록 한다.
폴더 선택 경로 얻기 -> 해당 경로내 파일 검색 -> 시간 얻기 -> isDot -> 파일명 변경 -> 계속
1. 폴더 경로 얻기.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ITEMIDLIST *pidBrowse; char pszPathname[MAX_PATH]; BROWSEINFO BrInfo; BrInfo.hwndOwner = GetSafeHwnd(); BrInfo.pidlRoot = NULL; memset(&BrInfo,0,sizeof(BrInfo)); BrInfo.pszDisplayName = pszPathname; BrInfo.lpszTitle="selec Folder"; BrInfo.ulFlags = BIF_RETURNONLYFSDIRS; pidBrowse = SHBrowseForFolder(&BrInfo); if(pidBrowse != NULL) { BOOL bSuccess = ::SHGetPathFromIDList(pidBrowse,pszPathname); if(bSuccess) { m_strPath = pszPathname; UpdateData(FALSE); } else{ MessageBox("wrong Folder naem!","lol",MB_ICONASTERISK); } } | cs |
2. 시간 얻기
3. 경로내 파일 검색
1 2 3 4 5 6 7 8 | CFileFind finder; bool working = finder.FindFile(m_strPath+"\\*.*"); while(working) { working = finder.FindNextFile(); } | cs |
4. IsDots()
폴더를 검색하면 상위 폴더를 보는 . 과 .. 이 있기때문에 이를 걸러주어야함.
1 2 3 4 5 6 7 8 9 10 | if(finder.IsDots()) continue; ex)CFileFind finder; bool working = finder.FindFile(m_strPath+"\\*.*"); while(working) { if(finder.IsDots()) continue; working = finder.FindNextFile(); } | cs |
5. 파일명 변경
CFile::Rename(strFindname,strTemp);
첫번째 인자는 전체 경로를 포함한 이전 파일명, 두번째 인자는 전체 경로를 포함한 새로 바뀔 파일명