package main
import (
"fmt"
"io/ioutil"
"path"
)
//获取文件夹中所有文件
func GetAllFile(pathname string) []string {
rd,_ := ioutil.ReadDir(pathname)
var filePath []string
for _, fi := range rd {
if fi.IsDir() {
filePath = append(filePath, pathname + "/" + fi.Name())
GetAllFile(pathname + fi.Name() + "\\")
}else {
filePath = append(filePath, pathname + "/" + fi.Name())
}
}
return filePath
}
//获取文件夹中所有文件的后缀
func GetSuffixName(filePath string) string{
var fileSuffix string
fileSuffix = path.Ext(filePath)
return fileSuffix
}
func main(){
var filePath string
//输入文件夹所在路径,这里只是抛砖引玉举个例子具体的由开发者决定
fmt.Printf("Please enter filePath: ")
fmt.Scanln(&filePath)
result := GetAllFile(filePath)
for i:=0;i<len(result);i++{
suffixName := GetSuffixName(result[i])
fmt.Println(suffixName)
}
}