files

package module
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: BSD-3-Clause Imports: 11 Imported by: 8

README

files

Functions for querying files and paths.

Function signatures

func Exists(path string) bool
func IsFile(path string) bool
func IsSymlink(path string) bool
func IsFileOrSymlink(path string) bool
func IsDir(path string) bool
func Which(executable string) string
func WhichCached(executable string) string
func PathHas(executable string) bool
func PathHasCached(executable string) bool
func BinDirectory(filename string) bool
func DataReadyOnStdin() bool
func IsBinary(filename string) bool
func FilterOutBinaryFiles(filenames []string) []string
func TimestampedFilename(filename string) string
func ShortPath(path string) string
func FileHas(path, what string) bool
func ReadString(filename string) string
func CanRead(filename string) bool
func Relative(path string) string
func Touch(filename string) error
func ExistsCached(path string) bool
func ClearCache()
func RemoveFile(path string) error
func DirectoryWithFiles(path string) (bool, error)
func IsExecutable(path string) bool
func IsExecutableCached(path string) bool

General info

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinDirectory

func BinDirectory(filename string) bool

BinDirectory will check if the given filename is in one of these directories: /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin, ~/.bin, ~/bin, ~/.local/bin

func CanRead added in v1.1.0

func CanRead(filename string) bool

CanRead checks if 1 byte can actually be read from the given filename

func ClearCache added in v1.5.0

func ClearCache()

ClearCache clears all cache

func DataReadyOnStdin

func DataReadyOnStdin() bool

DataReadyOnStdin checks if data is ready on stdin

func DirectoryWithFiles added in v1.8.0

func DirectoryWithFiles(path string) (bool, error)

DirectoryWithFiles checks if the given path is a directory and contains at least one file

func Exists

func Exists(path string) bool

Exists checks if the given path exists

func ExistsCached added in v1.5.0

func ExistsCached(path string) bool

ExistsCached checks if the given path exists, using a cache for faster access. Assumes that the filesystem has not changed since the last check.

func FileHas

func FileHas(path, what string) bool

FileHas checks if the given file exists and contains the given string

func FilterOutBinaryFiles

func FilterOutBinaryFiles(filenames []string) []string

FilterOutBinaryFiles filters out files that are either binary or can not be read

func IsBinary added in v1.4.0

func IsBinary(filename string) bool

IsBinary returns true if the given filename can be read and is a binary file

func IsDir

func IsDir(path string) bool

IsDir checks if the given path exists and is a directory

func IsExecutable added in v1.9.0

func IsExecutable(path string) bool

IsExecutable checks if the given path exists and is executable

func IsExecutableCached added in v1.9.0

func IsExecutableCached(path string) bool

IsExecutableCached checks if the given path exists and is an executable file, with cache support. Assumes that the filesystem permissions have not changed since the last check.

func IsFile

func IsFile(path string) bool

IsFile checks if the given path exists and is a regular file

func IsFileOrSymlink(path string) bool

IsFileOrSymlink checks if the given path exists and is a regular file or a symbolic link

func IsSymlink(path string) bool

IsSymlink checks if the given path exists and is a symbolic link

func PathHas added in v1.7.0

func PathHas(executable string) bool

PathHas checks if the given executable is in $PATH

func PathHasCached added in v1.7.0

func PathHasCached(executable string) bool

PathHasCached checks if the given executable is in $PATH (looks in the cache first and then caches the result)

func ReadString added in v1.1.0

func ReadString(filename string) string

ReadString returns the contents of the given filename as a string. Returns an empty string if there were errors.

func Relative added in v1.4.2

func Relative(path string) string

Relative takes an absolute or relative path and attempts to return it relative to the current directory. If there are errors, it simply returns the given path.

func RemoveFile added in v1.5.0

func RemoveFile(path string) error

RemoveFile deletes a file, but it only returns an error if the file both exists and also could not be removed

func ShortPath

func ShortPath(path string) string

ShortPath replaces the home directory with ~ in a given path. The given path is expected to contain the home directory path either 0 or 1 times, and if it contains the path to the home directory, it is expected to be at the start of the given string.

func TimestampedFilename

func TimestampedFilename(filename string) string

TimestampedFilename prefixes the given filename with a timestamp

func Touch added in v1.5.0

func Touch(filename string) error

Touch behaves like "touch" on the command line, and creates a file or updates the timestamp

func Which

func Which(executable string) string

Which tries to find the given executable name in the $PATH Returns an empty string if not found.

func WhichCached added in v1.6.0

func WhichCached(executable string) string

WhichCached tries to find the given executable name in the $PATH, using a cache for faster access. Assumes that the $PATH environment variable has not changed since the last check.

Types

This section is empty.

Jump to

Keyboard shortcuts

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