CFindFile?
-
Can I use CFileFind to search for a specific file on my computer? I've seen that the class has to do with the CGopherFileFind and CFtpFileFind. So I guess it's perhaps impossible? I've tried this but nothing appears: void CFopiacjeDlg::OnButton1() { CFileFind finder; BOOL bWorking = finder.FindFile("Fcc32.exe"); while (bWorking) { bWorking = finder.FindNextFile(); AfxMessageBox(finder.GetFilePath()); } }
-
Can I use CFileFind to search for a specific file on my computer? I've seen that the class has to do with the CGopherFileFind and CFtpFileFind. So I guess it's perhaps impossible? I've tried this but nothing appears: void CFopiacjeDlg::OnButton1() { CFileFind finder; BOOL bWorking = finder.FindFile("Fcc32.exe"); while (bWorking) { bWorking = finder.FindNextFile(); AfxMessageBox(finder.GetFilePath()); } }
Findfile like that is only searching your current directory. (doth it search the PATH too? I can't remember.). But it isn't going to search your entire drive as you would want it to. I use findfile in a self recursive function (it calls itself). Like this, If you don't want the tree just chop those bits out. This is a version that fills a tree with directories. void CExIncView::FillDirTree() { char DRIVES[33]; DWORD DriveNumbers; DWORD j; int k,Image,ImageSelected; CString lString; HTREEITEM ParentList[33]; unsigned lDriveType; m_Messages = " "; UpdateData(FALSE); //For each drive collect all directories DriveNumbers = GetLogicalDrives(); j=1; for(j=1,k=0;k<32;k++,j*=2) { if( DriveNumbers & j ) { DRIVES[k] = 'A' + k; } else { DRIVES[k] = ' '; } } //TEMP Put drives into tree for(k=0;k<32;k++) { if( DRIVES[k] != ' ') { lString.Format("%c:",DRIVES[k]); lDriveType = GetDriveType(lString); switch(lDriveType) { case DRIVE_UNKNOWN ://The drive type cannot be determined. Image = 2; ImageSelected = 3; break; case DRIVE_NO_ROOT_DIR ://The root directory does not exist. Image = 2; ImageSelected = 3; break; case DRIVE_REMOVABLE ://The disk can be removed from the drive. Image = 0; ImageSelected = 1; break; case DRIVE_FIXED ://The disk cannot be removed from the drive. Image = 2; ImageSelected = 3; break; case DRIVE_REMOTE ://The drive is a remote (network) drive. Image = 2; ImageSelected = 3; break; case DRIVE_CDROM ://The drive is a CD-ROM drive. Image = 4; ImageSelected = 5; break; case DRIVE_RAMDISK ://The drive is a RAM disk. Image = 2; ImageSelected = 3; break; default: Image = 2; ImageSelected = 3; break; } //ParentList[k] = m_pDirTree.InsertItem(lString,TVI_ROOT,TVI_SORT); ParentList[k] = m_pDirTree.InsertItem(lString,Image,ImageSelected,TVI_ROOT,TVI_LAST); m_pDirTree.SetItemData( ParentList[k], (DWORD) 50 ); } else { ParentList[k] = NULL; } } //For each parent traverse directory tree for(k=0;k<32;k++) { if(ParentList[k] != NULL) { lString.Format("%c:",DRIVES[k]); SearchDir(lString,ParentList[k]); } } } SearchDir is the self recursive function. void CExIncView::SearchDir(CString sPath) { CString sFind,sTemp; CString sBase,sBase2; int Done; WIN32_FIND_DATA lpFindFileData; HANDLE Search