Looking at the structure of the tree today, I remember that the file storage is a typical tree structure, so based on the functions provided by MFC, write a code about file lookup.
- Because MFC classes are needed, it is necessary to associate MFC when building a console project.
- This code removes some other code generated by associating MFC, preserving the _tmain () function;
- Uses a wide character, so the wcout output is used
Function:
Shrinking a file on a specified disk allows for a simple fuzzy lookup.
1#include"stdafx.h"2#include"ListWindowsFile.h"3 4 #ifdef _DEBUG5 #defineNew Debug_new6 #endif7 8 9 using namespacestd;Ten One int_tmain (intARGC, tchar* argv[], tchar*envp[]) A { - intnRetCode =0; -SetLocale (Lc_all,"CHS"); the //find file with Rewindboard in file name in F drive -CString Path = TEXT ("f:\\"); -CString name = TEXT ("Rewindboard"); - findfilewindows (path, name); +System"Pause"); - returnnRetCode; + } A at voidFindfilewindows (CString basepath, CStringObject) - { - CFileFind Finder; - CString Prefilepath; - CString Nextfullname; - CString FileName; in -Prefilepath = BasePath + TEXT ("*.*"); to intIresult = Finder.findfile (Prefilepath);//traverse the entire folder + - while(0!=Iresult) the { *Iresult =Finder.findnextfilew (); $ Panax Notoginseng //determine if a folder - if(Finder.isdirectory () &&!finder.isdots ()) the { +Nextfullname =Finder.getfilepath (); AFileName =finder.getfilename (); the if(Filename.find (Object,0) != -1) + { -Std::wcout << (LPCTSTR) Finder.getfilepath () <<Std::endl; $ } $Nextfullname + = TEXT ("\\"); -Findfilewindows (Nextfullname,Object); - } the Else //find out if the file is in this directory - {WuyiFileName =finder.getfilename (); the if(Filename.find (Object,0) != -1) - { WuStd::wcout << (LPCTSTR) Finder.getfilepath () <<Std::endl; - } About } $ } -}
Operation Result:
File Lookup under Windows