Documentation
¶
Overview ¶
Package files provides utilities for common file and directory operations.
Index ¶
- Constants
- Variables
- func CloseAndClean(f *os.File)
- func CollapseHomeDir(p string) string
- func Copy(from, to string) error
- func CreateTemp(prefix, ext string) (*os.File, error)
- func CreateTempFileWithData(d []byte, extension string) (*os.File, error)
- func Empty(s string) bool
- func EnsureSuffix(s, suffix string) string
- func Exists(s string) bool
- func ExistsErr(p string) error
- func ExpandHomeDir(s string) string
- func Find(root, pattern string) ([]string, error)
- func FindByExtList(root string, ext ...string) ([]string, error)
- func IsFile(path string) bool
- func JSONRead[T any](p string, v *T) error
- func JSONWrite[T any](p string, v *T, force bool) (bool, error)
- func List(root, pattern string) ([]string, error)
- func ListRecursive(root, pattern string) ([]string, error)
- func ListRootFolders(root string, ignore ...string) ([]string, error)
- func MkdirAll(s ...string) error
- func ModTime(s, format string) string
- func PrioritizeFile(files []string, name string)
- func Remove(s string) error
- func RemoveAll(s string) error
- func RemoveEmptyDirs(root string) error
- func RemoveFilepath(fname string) error
- func Rename(oldPath, newName string) error
- func SizeBytes(s string) int64
- func SizeFormatted(f string) string
- func StripSuffixes(p string) string
- func Touch(s string, existsOK bool) (*os.File, error)
Constants ¶
const ( DirPerm = 0o755 // Permissions for new directories. FilePerm = 0o644 // Permissions for new files. )
Variables ¶
Functions ¶
func CloseAndClean ¶
CloseAndClean closes the provided file and deletes the associated temporary file.
func CollapseHomeDir ¶
CollapseHomeDir replaces the home directory with a tilde (~).
func CreateTemp ¶
CreateTemp Creates a temporary file with the provided prefix.
func CreateTempFileWithData ¶
CreateTempFileWithData creates a temporary file and writes the provided data to it.
func EnsureSuffix ¶
EnsureSuffix appends the specified suffix to the filename.
func ExpandHomeDir ¶
func JSONWrite ¶
JSONWrite writes the provided data as JSON to the specified file. It uses generics to accept any type `T`.
func ListRecursive ¶
func ListRootFolders ¶
ListRootFolders returns a list of root folders.
func PrioritizeFile ¶
PrioritizeFile moves a file to the front of the list.
func RemoveEmptyDirs ¶
RemoveEmptyDirs removes empty directories.
func RemoveFilepath ¶
RemoveFilepath removes the file and its parent directory if empty.
func SizeFormatted ¶ added in v0.1.25
func StripSuffixes ¶
StripSuffixes removes all suffixes from the path.
Types ¶
This section is empty.