批量重命名文件
go
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
func Rename(path string) {
files, err := ioutil.ReadDir(path)
if err != nil {
fmt.Print(err)
return
}
for _, file := range files {
ofn := file.Name()
fmt.Print(ofn)
s1 := strings.ReplaceAll(ofn, "[", "")
s2 := strings.ReplaceAll(s1, "] ", "_")
os.Rename(path+"\\"+file.Name(), path+"\\"+s2)
}
}
func main() {
Rename("./Kubernetes/")
}