dirs

package
v1.1.17 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: BSD-3-Clause Imports: 10 Imported by: 16

Documentation

Overview

Package dirs provides various utility functions in dealing with directories such as a list of all the files with a given (set of) extensions and finding paths within the Go source directory (GOPATH, etc)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllFiles added in v0.9.11

func AllFiles(path string) ([]string, error)

AllFiles returns a slice of all the files, recursively, within a given directory Due to the nature of the filepath.Walk function, the first entry will be the directory itself, for reference -- just skip past that if you don't need it.

func DirFS added in v1.1.12

func DirFS(fpath string) (fs.FS, string, error)

DirFS returns the directory part of given file path as an os.DirFS and the filename as a string. These can then be used to access the file using the FS-based interface, consistent with embed and other use-cases.

func Dirs

func Dirs(path string) []string

Dirs returns a slice of all the directories within a given directory

func ExtFileNames

func ExtFileNames(path string, exts []string) []string

ExtFileNames returns all the file names with given extension(s) in directory in sorted order (if exts is empty then all files are returned)

func ExtFiles

func ExtFiles(path string, exts []string) []os.FileInfo

ExtFiles returns all the FileInfo's for files with given extension(s) in directory in sorted order (if exts is empty then all files are returned). In case of error, returns nil.

func FileExists added in v1.1.12

func FileExists(filePath string) (bool, error)

FileExists checks whether given file exists, returning true if so, false if not, and error if there is an error in accessing the file.

func FileExistsFS added in v1.1.12

func FileExistsFS(fsys fs.FS, filePath string) (bool, error)

FileExistsFS checks whether given file exists, returning true if so, false if not, and error if there is an error in accessing the file.

func FindFileOnPaths added in v1.1.12

func FindFileOnPaths(paths []string, file string) (string, error)

FindFileOnPaths attempts to locate given file on given list of paths, returning the full Abs path to file if found, else error

func GoSrcDir

func GoSrcDir(dir string) (absDir string, err error)

GoSrcDir tries to locate dir in GOPATH/src/ or GOROOT/src/pkg/ and returns its full path. GOPATH may contain a list of paths. From Robin Elkind github.com/mewkiz/pkg

func HasFile added in v0.9.11

func HasFile(path, file string) bool

HasFile returns true if given directory has given file (exact match)

func LatestMod

func LatestMod(path string, exts []string) time.Time

LatestMod returns the latest (most recent) modification time for any of the files in the directory (optionally filtered by extension(s) if exts != nil) if no files or error, returns zero time value

func SplitExt added in v1.0.1

func SplitExt(fname string) (fbase, ext string)

SplitExt returns the base of the file name without extension, and the extension

Types

This section is empty.

Jump to

Keyboard shortcuts

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