golang批量修改文件名

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

func main()  {
	path := "C:\\Users\\Administrator\\Downloads\\实用go语言学习"

	files, err := ioutil.ReadDir(path)
	if err != nil {
		log.Fatal(err)
	}

	for index, f := range files {
		fmt.Println(f.Name())
		os.Rename(path +"\\" + f.Name(), path +"\\" + 
fmt.Sprintf("实用go语言学习%02d.html", index))
	}
}

  

  

转载于:https://www.cnblogs.com/LittleLee/p/9448650.html

你可能感兴趣的:(golang批量修改文件名)