add: file export for table

This commit is contained in:
2024-08-28 14:35:44 +08:00
parent d9f84fc807
commit c80842087d
6 changed files with 67 additions and 59 deletions

27
lib/file/file.go Normal file
View File

@@ -0,0 +1,27 @@
package file
import (
"os"
"path/filepath"
)
func GetFileAndDirCount(dir string) (int, int, error) {
var fileCount, dirCount int
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if path == dir {
return nil // 跳过当前目录
}
if info.IsDir() {
dirCount++
} else {
fileCount++
}
return nil
})
return fileCount, dirCount, err
}