func RenamePic(c *gin.Context) {
dir:="C:\\Users\\cixu\\Desktop\\100D5600-3"
// 遍历文件夹,获取文件路径
paths := make([]string, 0)
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
paths = append(paths, path)
}
return nil
})
pattern:="" //重命名图片的前缀
// 遍历文件路径,修改文件名
for i, path := range paths {
newPath := filepath.Join(filepath.Dir(path), fmt.Sprintf("%s%d",pattern, i+1)+filepath.Ext(path))
os.Rename(path, newPath)
}
c.JSON(http.StatusOK,gin.H{"value":pattern})
}
有疑问加站长微信联系(非本文作者)