Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TreeNode ¶
type TreeNode struct { //node name 节点名称 Name string //node base name does not contain extension 节点名称 不包含扩展名 BaseName string //node extension 节点扩展名 ExtName string //current dir name 当前节点所在文件夹名称 CurrDirName string //base dir 当前节点所在文件夹路径地址 不包含当前节点所在文件夹 BaseDirPath string //is dir 是否文件夹 IsDir bool //full path 完整路径 FullPath string //file info os.DirEntry.Info() FileInfo os.FileInfo //file mode os.DirEntry.Type() Type fs.FileMode //array of subordinate nodes 子节点数组 Children []*TreeNode }
TreeNode Directory Tree Node
目录树节点
func Tree ¶
Tree
Get directory tree recursively 递归获取目录树 ¶
param: name dir path 目录路径地址
param: matchExt match extension map nil all files 匹配扩展名Map
param: sortFunc sort function nil no sort 排序函数
return:
Example ¶
package main import ( "fmt" "github.com/guolei19850528/go_pkgs/dir/dirtree" "sort" "strconv" ) func main() { name := "/Users/yourname/images" matchExt := map[string]string{ ".png": ".png", } sortFunc := func(dirTreeNodes []*dirtree.TreeNode) { sort.Slice(dirTreeNodes, func(i, j int) bool { sortKey1, err1 := strconv.ParseInt(dirTreeNodes[i].BaseName, 10, 32) sortKey2, err2 := strconv.ParseInt(dirTreeNodes[j].BaseName, 10, 32) if err1 == nil && err2 == nil { return sortKey1 < sortKey2 } return dirTreeNodes[i].BaseName < dirTreeNodes[j].BaseName }) } dirTree := dirtree.Tree(name, matchExt, sortFunc) fmt.Println(dirTree) }
Output:
Click to show internal directories.
Click to hide internal directories.