files

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 4 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecsInPath

func ExecsInPath(path string, lookalike func(string) bool) ([]string, error)

ExecsInPath returns a list of executables in the given path. The returned paths are absolute.

The given path should be an absolute path to a directory. If it's not a directory, the function will not proceed and return a nil slice.

lookalike accepts a function that returns true if the file name matches what we are expecting. Example:

func looksLikePip(name string) bool {
	var pipFileRegex = regexp.MustCompile(`^pip3(\d(\.\d\d?)?)?$`)
	return pipFileRegex.MatchString(name)
}

func FilesInPath added in v0.1.0

func FilesInPath(path string,
	lookalike func(string) bool,
	additionalChecks ...func(fs.FileInfo) bool) ([]string, error)

FilesInPath returns a list of files in the given path. The returned paths are absolute.

The given path should be an absolute path to a directory. If it's not a directory, the function will not proceed and return a nil slice.

lookalike accepts a function that returns true if the file name matches what we are expecting. Example:

func looksLikePip(name string) bool {
	var pipFileRegex = regexp.MustCompile(`^pip3(\d(\.\d\d?)?)?$`)
	return pipFileRegex.MatchString(name)
}

additionalChecks accepts a list of functions that returns true if the file meets the requirements. Example:

func IsExecutable(info fs.FileInfo) bool {
	return strings.ToLower(filepath.Ext(info.Name())) == ".exe"
}

func IsDir

func IsDir(path string) bool

IsDir returns true if the given path exists and is a directory. It delegates to os.Stat and FileInfo.IsDir.

func IsExecutable

func IsExecutable(info fs.FileInfo) bool

IsExecutable returns true if the given file info is executable. On Windows, it just checks if the file extension is ".exe" or not.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL