package pathutil
import "github.com/bitrise-io/go-utils/pathutil"
Example¶
Code:play
package main import ( "fmt" "strings" "github.com/bitrise-io/go-utils/pathutil" ) func main() { pths, err := pathutil.FilterPaths( []string{"/app2.apk", "/MyApp.ipa", "/app1.apk"}, pathutil.ExtensionFilter(".apk", true), ) if err != nil { panic(err) } pths, err = pathutil.SortPathsByComponents(pths) if err != nil { panic(err) } fmt.Println(strings.Join(pths, ", ")) }
Output:
/app1.apk, /app2.apk
Index ¶
- func AbsPath(pth string) (string, error)
- func ChangeDirForFunction(dir string, fn func()) error
- func CurrentWorkingDirectoryAbsolutePath() (string, error)
- func EnsureDirExist(dir string) error
- func EscapeGlobPath(path string) string
- func ExpandTilde(pth string) (string, error)
- func FileContainsFilter(pth, str string) (bool, error)
- func FilterPaths(fileList []string, filters ...FilterFunc) ([]string, error)
- func GetFileName(path string) string
- func IsDirExists(pth string) (bool, error)
- func IsPathExists(pth string) (bool, error)
- func IsRelativePath(pth string) bool
- func ListEntries(dir string, filters ...FilterFunc) ([]string, error)
- func ListPathInDirSortedByComponents(searchDir string, relPath bool) ([]string, error)
- func NormalizedOSTempDirPath(tmpDirNamePrefix string) (retPth string, err error)
- func PathCheckAndInfos(pth string) (os.FileInfo, bool, error)
- func RevokableChangeDir(dir string) (func() error, error)
- func SortPathsByComponents(paths []string) ([]string, error)
- func UserHomeDir() string
- type BySortablePathComponents
- func (s BySortablePathComponents) Len() int
- func (s BySortablePathComponents) Less(i, j int) bool
- func (s BySortablePathComponents) Swap(i, j int)
- type FilterFunc
- func BaseFilter(base string, allowed bool) FilterFunc
- func ComponentFilter(component string, allowed bool) FilterFunc
- func ComponentWithExtensionFilter(ext string, allowed bool) FilterFunc
- func DirectoryContainsFileFilter(fileName string) FilterFunc
- func ExtensionFilter(ext string, allowed bool) FilterFunc
- func InDirectoryFilter(dir string, allowed bool) FilterFunc
- func IsDirectoryFilter(allowed bool) FilterFunc
- func RegexpFilter(pattern string, allowed bool) FilterFunc
- type PathModifier
- type SortablePath
Examples ¶
Functions ¶
func AbsPath ¶
AbsPath expands ENV vars and the ~ character
then call Go's Abs
func ChangeDirForFunction ¶
ChangeDirForFunction ...
func CurrentWorkingDirectoryAbsolutePath ¶
CurrentWorkingDirectoryAbsolutePath ...
func EnsureDirExist ¶
EnsureDirExist ...
func EscapeGlobPath ¶
EscapeGlobPath escapes a partial path, determined at runtime, used as a parameter for filepath.Glob
func ExpandTilde ¶
ExpandTilde ...
func FileContainsFilter ¶
FileContainsFilter ...
func FilterPaths ¶
func FilterPaths(fileList []string, filters ...FilterFunc) ([]string, error)
FilterPaths ...
func GetFileName ¶
GetFileName returns the name of the file from a given path or the name of the directory if it is a directory
func IsDirExists ¶
IsDirExists ...
func IsPathExists ¶
IsPathExists ...
func IsRelativePath ¶
IsRelativePath ...
func ListEntries ¶
func ListEntries(dir string, filters ...FilterFunc) ([]string, error)
ListEntries filters contents of a directory using the provided filters
func ListPathInDirSortedByComponents ¶
ListPathInDirSortedByComponents ...
func NormalizedOSTempDirPath ¶
NormalizedOSTempDirPath ... Creates a temp dir, and returns its path. If tmpDirNamePrefix is provided it'll be used
as the tmp dir's name prefix.
Normalized: it's guaranteed that the path won't end with '/'.
func PathCheckAndInfos ¶
PathCheckAndInfos ... Returns: 1. file info or nil 2. bool, indicating whether the path exists 3. error, if any error happens during the check
func RevokableChangeDir ¶
RevokableChangeDir ...
func SortPathsByComponents ¶
SortPathsByComponents ...
func UserHomeDir ¶
func UserHomeDir() string
UserHomeDir ...
Types ¶
type BySortablePathComponents ¶
type BySortablePathComponents []SortablePath
BySortablePathComponents ..
func (BySortablePathComponents) Len ¶
func (s BySortablePathComponents) Len() int
func (BySortablePathComponents) Less ¶
func (s BySortablePathComponents) Less(i, j int) bool
func (BySortablePathComponents) Swap ¶
func (s BySortablePathComponents) Swap(i, j int)
type FilterFunc ¶
FilterFunc ...
func BaseFilter ¶
func BaseFilter(base string, allowed bool) FilterFunc
BaseFilter ...
func ComponentFilter ¶
func ComponentFilter(component string, allowed bool) FilterFunc
ComponentFilter ...
func ComponentWithExtensionFilter ¶
func ComponentWithExtensionFilter(ext string, allowed bool) FilterFunc
ComponentWithExtensionFilter ...
func DirectoryContainsFileFilter ¶
func DirectoryContainsFileFilter(fileName string) FilterFunc
DirectoryContainsFileFilter returns a FilterFunc that checks if a directory contains a file
func ExtensionFilter ¶
func ExtensionFilter(ext string, allowed bool) FilterFunc
ExtensionFilter ...
func InDirectoryFilter ¶
func InDirectoryFilter(dir string, allowed bool) FilterFunc
InDirectoryFilter ...
func IsDirectoryFilter ¶
func IsDirectoryFilter(allowed bool) FilterFunc
IsDirectoryFilter ...
func RegexpFilter ¶
func RegexpFilter(pattern string, allowed bool) FilterFunc
RegexpFilter ...
type PathModifier ¶
PathModifier ...
func NewPathModifier ¶
func NewPathModifier() PathModifier
NewPathModifier ...
type SortablePath ¶
SortablePath ...
func NewSortablePath ¶
func NewSortablePath(pth string) (SortablePath, error)
NewSortablePath ...
Source Files ¶
path_filter.go pathutil.go sortable_path.go
- Version
- v1.0.15 (latest)
- Published
- May 13, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 2 months ago –
Tools for package owners.