例如有以下路径:
root@node1:/tmp/zz# tree /tmp/oss/
/tmp/oss/
└── unsealed
├── s-t01003-100
├── s-t01003-1000
├── s-t01003-74
└── s-t01003-75
2 directories, 3 files
root@node1:/tmp/zz#
遍历指定目录:
package main
import (
"fmt"
"os"
"path/filepath"
)
const (
DIRS= "/tmp/oss/"
)
func main() {
fmt.Println("vim-go")
filepath.Walk(DIRS,
func(path string, f os.FileInfo, err error) error {
if f == nil {
return err
}
if f.IsDir() {
fmt.Println("dir:", path)
return nil
}
fmt.Println("file:", path, filepath.Base(path))
sid := "s-t01003-74"
if filepath.Base(path) == sid {
fmt.Println("upload path:", path)
}
return nil
})
}
执行结果:
root@node1:/tmp/zz# go run main.go vim-go dir: /tmp/oss/ dir: /tmp/oss/unsealed file: /tmp/oss/unsealed/s-t01003-100 s-t01003-100 dir: /tmp/oss/unsealed/s-t01003-1000 file: /tmp/oss/unsealed/s-t01003-74 s-t01003-74 upload path: /tmp/oss/unsealed/s-t01003-74 file: /tmp/oss/unsealed/s-t01003-75 s-t01003-75 root@node1:/tmp/zz#



