This is a creation in Article, where the information may have evolved or changed.
1 Package Main2 3 Import (4 "FMT"5 "Io/ioutil"6 "OS"7 "Path/filepath"8 "Strings"9 )Ten One varMatchCount =0 A varch = make (chanint, +) - -Func FindFile (pathstring, textstring) { the varPatharray [ -]string - varCount =0 -FilePath. Walk (Path, func (pathstring, Info os. FileInfo, err Error) error { - ifErr! =Nil { + } - //Find Text + if!info. Isdir () { A ifInfo. Size () <1024x768*1024x768 { atPatharray[count] =Path -count++ - ifCount >= - { -Count =0 -Go FindText (patharray[0: -], text) -<-CH in } - } to } + returnNil - }) theGo FindText (patharray[0: Count], text) *<-CH $ Panax NotoginsengFmt. Printf ("We found a total of%d matching files", MatchCount) - the } + AFunc findText (Paths []string, textstring) { the for_, Path: =range Paths { +FI, err: =OS. Open (PATH) - ifErr! =Nil { $ Panic (Err) $ } - defer fi. Close () -FD, Err: =Ioutil. ReadAll (FI) the ifErr! =Nil { - Panic (Err)Wuyi } the - ifStrings. Index (string(FD), text) >-1 { Wumatchcount++ - FMT. Println (PATH) About } $ } -CH <-1 - } - A Func Main () { +Args: =OS. Args the ifLen (args) <3 { -Fmt. Println ("requires two parameters path text") $ return the } thePath: = args[1] theText: = args[2] the -_, Err: =OS. Stat (PATH) in the ifErr! =Nil { theFmt. Println ("path does not exist") About}Else { the findfile (path, text) the } the}
When the counter increases, it should be locked.