fs

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const FileBackupSuffix = ".bak"

Variables

This section is empty.

Functions

func AbsPath

func AbsPath(rootPath string, path string) string

AbsPath ensures that path is an absolute path. If it isn't, it is joined with rootPath.

func AbsPaths

func AbsPaths(rootPath string, paths []string) []string

AbsPaths ensures that all elements in paths are absolute paths. If an element is not an absolute path, it is joined with rootPath.

func BackupFile

func BackupFile(filepath string) error

BackupFile renames a file to <OldName><FileBackupSuffix>.

func DirsExist

func DirsExist(paths ...string) error

DirsExist runs DirExists for multiple paths.

func FileExists

func FileExists(path string) bool

FileExists returns true if path exist and is a file

func FileGlob

func FileGlob(pattern string) ([]string, error)

FileGlob resolves the pattern to file paths. If the pattern is an absolute path, absolute paths are returned, otherwise relative paths. Files are resolved in the same way then filepath.Glob() does, with the following exceptions:

  • it also supports '**' to match files and directories recursively,
  • it only returns paths to files, no directory paths,
  • if a part of the pattern is a path and it does not exist an error that can be tested with os.IsNotExist() is returned.

If a globPath doesn't match any files an empty []string is returned and error is nil

func FileHasOwnerExecPerm

func FileHasOwnerExecPerm(p string) (bool, error)

FileHasOwnerExecPerm returns true if the executable mode bit for the file owner is set.

func FileReadLine

func FileReadLine(path string) (string, error)

FileReadLine reads the first line from a file

func FileSize

func FileSize(path string) (int64, error)

FileSize returns the size of a file in Bytes

func FindDirInParentDirs

func FindDirInParentDirs(startPath, dirname string) (string, error)

FindDirInParentDirs finds a directory in startPath or its parent directories. The function starts looking for a directory called dirname in startPath and then checks recursively its parent directories. It returns the absolute path of the first match. If it reaches the root directory without finding the directory it returns os.ErrNotExist.

func FindFileInParentDirs

func FindFileInParentDirs(startPath, filename string) (string, error)

FindFileInParentDirs finds a file in startPath or its parent directories. The function starts looking for a file called filename in startPath and then checks recursively its parent directories. It returns the absolute path of the first match. If it reaches the root directory without finding the file it returns os.ErrNotExist.

func FindFilesInSubDir

func FindFilesInSubDir(searchDir, filename string, maxdepth int) ([]string, error)

FindFilesInSubDir returns all directories that contain filename that are in searchDir. The function descends up to maxdepth levels of directories below searchDir

func IsDir

func IsDir(path string) (bool, error)

IsDir returns true if the path is a directory. If the directory does not exist, the error from os.Stat() is returned.

func IsFile

func IsFile(path string) (bool, error)

IsFile returns true if path is a file. If the path does not exist an error is returned

func IsRegularFile

func IsRegularFile(path string) (bool, error)

IsRegularFile returns true if path is a regular file. If the directory does not exist, the error from os.Stat() is returned.

func MatchGlob

func MatchGlob(pattern, path string) (bool, error)

func Mkdir

func Mkdir(path string) error

Mkdir creates recursively directories

func OwnerHasExecPerm

func OwnerHasExecPerm(m fs.FileMode) bool

OwnerHasExecPerm returns true if the executable mode bit in m is set.

func PathsJoin

func PathsJoin(rootPath string, relPaths []string) []string

PathsJoin returns a list where all paths in relPaths are prefixed with rootPath

func RealPath

func RealPath(path string) (string, error)

RealPath resolves all symlinks and returns the absolute path.

func RealPathRel

func RealPathRel(basepath, path string) (string, error)

RealPath resolves all symlinks and returns the path relative to basepath.

func SameFile

func SameFile(a, b string) (bool, error)

SameFile calls os.Samefile(), if one of the files does not exist, the error from os.Stat() is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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