Documentation
¶
Overview ¶
Example ¶
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
- 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 ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeDirForFunction ¶
ChangeDirForFunction ...
func CurrentWorkingDirectoryAbsolutePath ¶
CurrentWorkingDirectoryAbsolutePath ...
func EscapeGlobPath ¶
EscapeGlobPath escapes a partial path, determined at runtime, used as a parameter for filepath.Glob
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 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 ...
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 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 ...
type PathModifier ¶ added in v1.0.1
PathModifier ...
type SortablePath ¶
SortablePath ...