Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TreeNode ¶ added in v1.0.3
type TreeNode struct { //node name example:"1.png" Name string //node base name does not contain extension example:"1" BaseName string //node extension example:".png" ExtName string //current dir name example: "a" CurrDirName string //base dir path example:"/Users/guolei/images" BaseDirPath string //is dir IsDir bool //full path example:"/Users/guolei/images/a/1.png" FullPath string //file info FileInfo os.FileInfo //file mode Type fs.FileMode //array of subordinate nodes Children []*TreeNode }
TreeNode Directory Tree Node
func Tree ¶ added in v1.0.3
Tree
param: name dir path param: matchExt match extension map param: sortFunc sort function return:
Example ¶
package main import ( "fmt" "github.com/guolei19850528/go_dirtree" "sort" "strconv" ) func main() { name := "/Users/yourname/images" matchExt := map[string]string{ ".png": ".png", } sortFunc := func(dirTreeNodes []*go_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 := go_dirtree.Tree(name, matchExt, sortFunc) fmt.Println(dirTree) }
Output:
Click to show internal directories.
Click to hide internal directories.