File Lookup under Windows

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.