This is a created article in which the information may have evolved or changed.
Package Mainimport ("FMT" "OS" "Path/filepath" "RegExp") func main () {//command-line arguments args: = os. args//Check parameters If Len (args) = = 1 {fmt. PRINTLN ("FF is a file Find tool. Use like Bottom ") fmt. PRINTLN ("ff [dir] [regexp]") Return}if len (args) < 3 {FMT. Println ("Args < 3") Return}filename: = Args[1]pattern: = Args[2]file, err: = OS. Open (fileName) if err! = Nil {fmt. PRINTLN (Err) Return}fi, err: = file. Stat () if err! = Nil {fmt. PRINTLN (Err) return}if!fi. Isdir () {fmt. Println (FileName, "is not a dir")}reg, err: = Regexp.compile (pattern) if err! = Nil {fmt. PRINTLN (ERR) return}//traverses the directory filepath. Walk (Filename,func (path string, F OS. FileInfo, err Error) error {if Err! = Nil {fmt. PRINTLN (ERR) return err}if F.isdir () {return nil}//match directory matched: = Reg. Matchstring (F.name ()) if matched {fmt. Println (path)}return nil})}