使用filepath.Glob递归获取目录下的文件及子文件

5年以前  |  阅读数:1781 次  |  编程语言:Golang 
package utils

import (
    "io/ioutil"
    "os"
    "path/filepath"
    "strings"
)

//GetAllFileIncludeSubFolder 递归获取某个目录下的所有文件
func GetAllFileIncludeSubFolder(folder string) ([]string, error) {
    searchPath := folder
    if strings.HasSuffix(folder, "/") {
        searchPath = searchPath + "*"
    } else {
        searchPath = searchPath + "/*"
    }

    return filepath.Glob(searchPath)
}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8