rename 批量重命名 文件重命名 文件压缩
package zip import ( "archive/zip" "io" "os" ) func f() { var Zip func(filePath []string, Result string) error Zip = func(filePath []string, Result string) error { archive, err := os.Create(Result) if err != nil { panic(err) } defer archive.Close() zipWriter := zip.NewWriter(archive) for _, path := range filePath { f, err := os.Open(path) if err != nil { panic(err) } else { w, err := zipWriter.Create(path) if err != nil { panic(err) } if _, err := io.Copy(w, f); err != nil { panic(err) } } defer f.Close() } zipWriter.Close() return nil } Result := "Result.zip" filePath := []string{"a/a1.txt", "b/b1.txt", "a/捕获.PNG"} err := Zip(filePath, Result) if err != nil { panic(err) }
Linux中rename命令用法学习 修改文件名_Linux教程_Linux公社-Linux系统门户
8 -rw-r--r-- 1 root root 4108 Apr 28 19:13 myv_middle500115361524914013TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 19:15 myv_middle04108TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 19:29 myv_middle04940TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 19:40 myv_middle05610TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 19:46 myv_middle06012TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 19:48 myv_middle06108TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 19:49 myv_middle06161TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:22 myv_middle08170TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:23 myv_middle08217TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:25 myv_middle08346TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 18:47 myv_middle04998847TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 19:26 myv_middle0189TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 19:30 myv_middle0447TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 19:31 myv_middle0510TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 19:32 myv_middle0530TEST.avi 4 drwxr-xr-x 2 root root 4096 Apr 28 09:50 myv_tmp 6524 -rw-r--r-- 1 root root 6678642 Apr 20 11:01 pack.json 4 -rw-r--r-- 1 root root 371 Apr 20 10:27 rename.old.py 4 -rw-r--r-- 1 root root 1621 Apr 20 11:26 t.py [root@iZ2zed2wapjytnh9c70enuZ dlDBimg]# ll -as [root@mytest dlDBimg]# rename myv_middle myv_middleA myv_middle* [root@mytest dlDBimg]# ll 8 -rw-r--r-- 1 root root 4108 Apr 28 19:25 myv_middleA036TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 19:44 myv_middleA05845TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 19:46 myv_middleA0603TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:0 myv_middleA06884TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:0 myv_middleA06917TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:09 myv_middleA07399TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:12 myv_middleA07520TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:12 myv_middleA07521TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:16 myv_middleA07806TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:20 myv_middleA0804TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:21 myv_middleA08103TEST.avi 156908 -rw-r--r-- 1 root root 160673652 Apr 28 20:26 myv_middleA08397TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 28 20:29 myv_middleA08567TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 18:29 myv_middleA097777TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 18:31 myv_middleA097903TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 18:36 myv_middleA098189TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 18:38 myv_middleA098324TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 18:41 myv_middleA098497TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 18:49 myv_middleA098942TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 19:12 myv_middleA0373TEST.avi 8 -rw-r--r-- 1 root root 4108 Apr 29 19:17 myv_middleA0675TEST.avi
import ( "os" "path/filepath" "strings" ) func myRename() { p := "D:\\搜狗高速下载\\" n := "test.DVD版.01.HD1080p.mp4" err := os.Rename(p+n, p+"123.mp4") if err != nil { } files, _ := filepath.Glob(p + "\\*") for _, v := range files { if strings.Contains(v, "DVD版") { n := strings.Replace(v, "test", "名义", 1) _ = os.Rename(v, n) } } _ = files print() }