1. Determine whether a file or folder exists.
If (! Pathfileexists (csfilepath ))
{: Createdirectory (csfilepath, null );}
2. Open the windows Type dialog box
Static tchar strdirname [max_path]; browseinfo Bi; cstring szstring = text ("select a folder"); bi. hwndowner =: getfocus (); bi. pidlroot = NULL; bi. pszdisplayname = strdirname; bi. lpsztitle = szstring; bi. ulflags = bif_browseforcomputer | bif_dontgobelowdomain | bif_returnonlyfsdirs; bi. lpfn = NULL; bi. lparam = 0; bi. iimage = 0; lpitemidlist pitemidlist =: shbrowseforfolder (& BI); If (pitemidlist = NULL) {return ;}:: shgetpathfromidlist (pitemidlist, strdirname );
3. traverse all files in the directory
CString csFolder = csGPSDataPath + _T("\\*.txt");CFileFind finder;BOOL bWorking = finder.FindFile(csFolder);while (bWorking){bWorking = finder.FindNextFile();if (finder.IsDots()){continue;}CString strPath = finder.GetFileName();CString strFile = csGPSDataPath + _T("\\") + strPath;vecAllFilePath.push_back(strFile);}finder.Close();
4. Open the dialog box that was last opened in Windows
BOOL CTestDlg::GetOpenSaveMRU(LPCTSTR strExtName,char *strMRUPath){HKEY hKEY;const char *mru="Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\OpenSaveMRU\\";CString strmru(mru);strmru += strExtName;long lRet = RegOpenKeyEx(HKEY_CURRENT_USER,strmru,0,KEY_READ,&hKEY);if (lRet != ERROR_SUCCESS ) {return FALSE;}DWORD keytype1 = REG_SZ;DWORD dwInBytes = 256;BYTE pInBuf[256];lRet = RegQueryValueEx(hKEY,"MRUList",NULL,&keytype1,pInBuf,&dwInBytes);if (lRet != ERROR_SUCCESS ) {return FALSE;}dwInBytes = 256;char strLast[] = {pInBuf[0],0};lRet = RegQueryValueEx(hKEY,(LPTSTR)strLast,NULL,&keytype1,(LPBYTE) strMRUPath,&dwInBytes);if (lRet != ERROR_SUCCESS) {return FALSE;}CString str1(strMRUPath);int idx=str1.ReverseFind('\\');strMRUPath[idx]=0;RegCloseKey(hKEY);return TRUE;}