main.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "path/filepath"
  6. "strings"
  7. )
  8. //// 生成插件命令到 sh文件
  9. //func main() {
  10. // //go build --buildmode=plugin -o ./so/pji/errorcode#1#21031701.so ./trigger/pji/diagnostics/errorcode#1#21031701/main/main.go
  11. // // 指定目录的路径
  12. // dirPath := "D:\\code\\cicv-data-closedloop\\trigger\\pji\\diagnostics"
  13. //
  14. // // 读取目录内容
  15. // files, err := os.ReadDir(dirPath)
  16. // if err != nil {
  17. // log.Fatal(err)
  18. // }
  19. //
  20. // // 遍历目录中的文件和子目录
  21. // content := ""
  22. // for _, file := range files {
  23. // // 如果是目录
  24. // if file.IsDir() {
  25. // // 打印子目录名称
  26. //
  27. // fileName := strings.Replace(strings.Replace(file.Name(), " ", "", -1), "\n", "", -1)
  28. // fmt.Println()
  29. // content = content + "go build --buildmode=plugin -o ./so/pji/" + fileName + ".so ./trigger/pji/diagnostics/" + fileName + "/main/main.go" + "\n"
  30. // }
  31. // }
  32. // util.WriteFile(content, "D:\\test.sh")
  33. //}
  34. func replaceSymbolInDir(root string, oldSymbol, newSymbol string) error {
  35. return filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
  36. if err != nil {
  37. return err
  38. }
  39. if info.IsDir() {
  40. // Rename directory
  41. newPath := strings.Replace(path, oldSymbol, newSymbol, -1)
  42. if newPath != path {
  43. fmt.Printf("Renaming %s to %s\n", path, newPath)
  44. return os.Rename(path, newPath)
  45. }
  46. }
  47. return nil
  48. })
  49. }
  50. func main() {
  51. rootDir := "D:\\code\\cicv-data-closedloop\\trigger\\pji\\diagnostics"
  52. oldSymbol := "#"
  53. newSymbol := "_"
  54. err := replaceSymbolInDir(rootDir, oldSymbol, newSymbol)
  55. if err != nil {
  56. fmt.Println("Error:", err)
  57. return
  58. }
  59. fmt.Println("Replacement completed successfully.")
  60. }