package main
import (
"fmt"
"io"
"os"
"strings"
)
func main() {
//源文件路径
srcFile := "/Users/pc/Desktop/goPro/"
//目标文件路径
bastFile := "./"
fmt.Println(srcFile)
fmt.Println(bastFile)
fmt.Println(judge(srcFile))
}
//判断目录项带有.mp4的文件
func judge(srcFile string) (bk []byte, err error) {
file1, err := os.OpenFile(srcFile, os.O_RDONLY, os.ModeDir)
if err != nil {
return
}
defer file1.Close()
//读取目录项
n1, err := file1.Readdir(-1)
if err != nil && err == io.EOF {
fmt.Println("读取目录成功")
return
}
//遍历切片n
bk1 := make([]string, 4096)
for _, info := range n1 {
if !info.IsDir() {
if strings.HasSuffix(info.Name(), ".mp4") {
bk1 = append(bk1, info.Name())
}
}
}
return
}
有疑问加站长微信联系(非本文作者)