Package Mainimport ("bytes" "FMT" "OS" "Os/exec" "Path/filepath" "Sync") type Jieguo struct {go_num intlock sync. Mutex}var searchname string = os. Args[1]var Search_result Chan string = Make (Chan string, 1) var nums chan int = make (chan int, 1) var x jieguo = Jieguo{go_n Um:0}func Main () {list: = []string{' D: ', ' E: ', ' F '}for _, I: = Range list {fmt. Println (i, searchname) go pan (i)}for {select {case x: = <-search_result:fmt. PRINTLN (x) case y: = <-nums:if y = = 0 {os. Exit (0)}}}}func pan (path string) {A: = Exec.command ("ls", path) result, E: = A.output () if E! = nil {fmt. Println (e)}z: = bytes. Split (result, []byte{10}) for _, I: = Range Z[:len (z)-1] {s: = path + "\ \" + String (i) fmt. PRINTLN (s) e = os. Chdir (s) if E = = nil {X.lock.lock () X.go_num = X.go_num + 1x. Lock.unlock () go func () {filepath. Walk (S, Walk) x.lock.lock () X.go_num = X.go_num-1nums <-x.go_numx. Lock.unlock ()} ()} else {fmt. PRINTLN (e) if string (i) = = Searchname {fmt. Println (s)}}}}func Walk (path string, info OS. FileInfo, err Error) error {If err! = Nil {return err}if!info. Isdir () && info. Name () = = searchname {search_result <-pathreturn nil}return Nil}
Wrote a computer search file in the Go language small thing