package main import ( "fmt" "os" "path/filepath" "strings" ) //// 生成插件命令到 sh文件 //func main() { // //go build --buildmode=plugin -o ./so/pji/errorcode#1#21031701.so ./trigger/pji/diagnostics/errorcode#1#21031701/main/main.go // // 指定目录的路径 // dirPath := "D:\\code\\cicv-data-closedloop\\trigger\\pji\\diagnostics" // // // 读取目录内容 // files, err := os.ReadDir(dirPath) // if err != nil { // log.Fatal(err) // } // // // 遍历目录中的文件和子目录 // content := "" // for _, file := range files { // // 如果是目录 // if file.IsDir() { // // 打印子目录名称 // // fileName := strings.Replace(strings.Replace(file.Name(), " ", "", -1), "\n", "", -1) // fmt.Println() // content = content + "go build --buildmode=plugin -o ./so/pji/" + fileName + ".so ./trigger/pji/diagnostics/" + fileName + "/main/main.go" + "\n" // } // } // util.WriteFile(content, "D:\\test.sh") //} func replaceSymbolInDir(root string, oldSymbol, newSymbol string) error { return filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if info.IsDir() { // Rename directory newPath := strings.Replace(path, oldSymbol, newSymbol, -1) if newPath != path { fmt.Printf("Renaming %s to %s\n", path, newPath) return os.Rename(path, newPath) } } return nil }) } func main() { rootDir := "D:\\code\\cicv-data-closedloop\\trigger\\pji\\diagnostics" oldSymbol := "#" newSymbol := "_" err := replaceSymbolInDir(rootDir, oldSymbol, newSymbol) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Replacement completed successfully.") }