1 Star 0 Fork 0

iceinto/gfutil

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gfile_sort.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
iceinto 提交于 2024-09-13 17:50 . v2 版本位置调整
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/elastic/beats/v7/kspkg/gf.
package gfile
import (
"strings"
"gitee.com/iceinto/gfutil/v2/container/garray"
)
// fileSortFunc is the comparison function for files.
// It sorts the array in order of: directory -> file.
// If `path1` and `path2` are the same type, it then sorts them as strings.
func fileSortFunc(path1, path2 string) int {
isDirPath1 := IsDir(path1)
isDirPath2 := IsDir(path2)
if isDirPath1 && !isDirPath2 {
return -1
}
if !isDirPath1 && isDirPath2 {
return 1
}
if n := strings.Compare(path1, path2); n != 0 {
return n
} else {
return -1
}
}
// SortFiles sorts the `files` in order of: directory -> file.
// Note that the item of `files` should be absolute path.
func SortFiles(files []string) []string {
array := garray.NewSortedStrArrayComparator(fileSortFunc)
array.Add(files...)
return array.Slice()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/iceinto/gfutil.git
git@gitee.com:iceinto/gfutil.git
iceinto
gfutil
gfutil
v2.0.0

搜索帮助