68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
var paths []string
|
|
rootDir, _ := os.Getwd()
|
|
paths, _ = GetAllFile(rootDir, paths, []string{".git", ".idea", ".vscode", ".gitignore", ".gitea", ".github", ".golangci.yml", "*.pyc"})
|
|
|
|
for _, fp := range paths {
|
|
fmt.Println(fp)
|
|
}
|
|
}
|
|
|
|
func GetAllFile(pathname string, s []string, filter []string) ([]string, error) {
|
|
rd, err := os.ReadDir(pathname)
|
|
if err != nil {
|
|
fmt.Println("read dir fail:", err)
|
|
return s, err
|
|
}
|
|
for _, fi := range rd {
|
|
// 检查文件名是否匹配任何一个过滤模式
|
|
matched := false
|
|
for _, item := range filter {
|
|
exists, err := filepath.Match(item, fi.Name())
|
|
if err != nil {
|
|
continue
|
|
}
|
|
if exists {
|
|
matched = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if matched {
|
|
continue
|
|
}
|
|
|
|
if fi.IsDir() {
|
|
fullDir := pathname + "/" + fi.Name()
|
|
s, err = GetAllFile(fullDir, s, filter)
|
|
if err != nil {
|
|
fmt.Println("read dir fail:", err)
|
|
return s, err
|
|
}
|
|
} else {
|
|
fullName := pathname + "/" + fi.Name()
|
|
s = append(s, fullName)
|
|
}
|
|
}
|
|
return s, nil
|
|
}
|
|
|
|
func In(target string, array []string) bool {
|
|
target = strings.Trim(target, "")
|
|
for _, v := range array {
|
|
if strings.Trim(v, "") == target {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|