|
|
@@ -8,10 +8,27 @@ import (
|
|
|
"sort"
|
|
|
)
|
|
|
|
|
|
-// @title FileExists
|
|
|
-// @description 检测文件是否存在
|
|
|
-// @param filePath 文件路径
|
|
|
-// @return bool 是否存在,error 是否成功
|
|
|
+// GetAllFilePath 获取指定目录内的文件和子目录的文件,递归获取
|
|
|
+func GetAllFilePath(filePaths []string, currentPath string) (excelPaths []string, err error) {
|
|
|
+ //2021-12-23
|
|
|
+ files, err := ioutil.ReadDir(currentPath)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("filepath.Glob error : %v\n", err)
|
|
|
+ return filePaths, err
|
|
|
+ }
|
|
|
+ for _, f := range files {
|
|
|
+ if f.IsDir() {
|
|
|
+ return GetAllFilePath(filePaths, filepath.Join(currentPath, f.Name()))
|
|
|
+ } else {
|
|
|
+ filePaths = append(filePaths, filepath.Join(currentPath, f.Name()))
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return filePaths, nil
|
|
|
+}
|
|
|
+
|
|
|
+// FileExists 检测文件是否存在
|
|
|
func FileExists(filePath string) (bool, error) {
|
|
|
_, err := os.Stat(filePath)
|
|
|
if err == nil {
|
|
|
@@ -38,6 +55,7 @@ func GetFileFromFolder(folder string) ([]string, error) {
|
|
|
return filePaths, nil
|
|
|
}
|
|
|
|
|
|
+// RemoveFiles 删除指定路径和指定后缀的文件
|
|
|
func RemoveFiles(folder, suffix string) error {
|
|
|
filePaths, err := GetFileFromFolder(folder)
|
|
|
|
|
|
@@ -60,8 +78,9 @@ func RemoveFiles(folder, suffix string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//2021-11-03
|
|
|
+// GetSubTitleByModTime 从指定路径获取字幕文件,按mod时间排序
|
|
|
func GetSubTitleByModTime(folder string) (string, error) {
|
|
|
+ //2021-11-03
|
|
|
filePaths := []string{}
|
|
|
files, err := ioutil.ReadDir(folder)
|
|
|
|