add: custom kpi and export log&cdr file
This commit is contained in:
27
lib/file/file.go
Normal file
27
lib/file/file.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user