filesystem

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFileWithUpdate

func CopyFileWithUpdate(srcFile, dstFile, startwith, replacement string, appendIfNoMatch bool) result.Result

CopyFileWithUpdate copies srcFile to dstFile replacing all the lines starting with startwith by replacement.

func CreateFolderIfNeeded

func CreateFolderIfNeeded(folderPath string) result.Result

CreateFolderIfNeeded creates a folder if it does NOT exists. Returns a string which describes what has been done, or an error message.

func CreateOrAppendIfNotInFile

func CreateOrAppendIfNotInFile(filePath, content string) (bool, error)

CreateOrAppendIfNotInFile checks if a content is already present inside a file. The content MUST be a FULL line (strict line equality) or a set of full lines with a '\n' between them. If the content is already present in the file, the file remains unchanged and the function returns false. Otherwise, the content is appended at the end of the file, and the function returns true.

func Exists

func Exists(filePath string) (bool, error)

Exists checks if a file exists. Returns true if the file exists, false otherwise.

func FloderContent

func FloderContent(folderPath string) ([]string, error)

FloderContent returns the list of elements (files, folders,...) inside a subtree.

func FolderExists

func FolderExists(folderPath string) (bool, error)

FolderExists checks if a folder exists. Return true if the folder exists, false otherwise. error != nil if a file exists and is not a folder (ie a regular file or link). TODO : return value is a bit overcomplicated

func FolderFiles

func FolderFiles(folderPath string) ([]string, error)

FolderFiles returns the list of regular files inside a subtree.

func HomeDir

func HomeDir() string

HomeDir gets the value of HOME environment variable. Exit(1) on failure.

func IsEmptyFolder

func IsEmptyFolder(folderPath string) (string, error)

EmptyFolder checks if a folder is empty. Returns a string explaining the folder status NOT_EXIST NOT_FOLDER NOT_EMPTY EMPTY or an error if diagnosis failed

func ReadFileAsBinary

func ReadFileAsBinary(filePath string) ([]byte, error)

ReadFileAsBinary gets the content of a binary file.

func ReadFileAsString

func ReadFileAsString(filePath string) (string, error)

ReadFileAsString gets the content of a text file.

func ReadFileAsStringOrEmptyIfNotExists

func ReadFileAsStringOrEmptyIfNotExists(filePath string) (string, error)

ReadFileAsStringOrEmptyIfNotExists gets the content of a text file. If the file does NOT exists, the method does NOT send an error but returns an empty string.

func RegularFileExists

func RegularFileExists(filePath string) (bool, error)

RegularFileExists checks if a regular file exists. Returns true if the file exists and is a regular file, false otherwise. error != nil if the file exists and is not a regular file (ie a directory). TODO : return value is a bit overcomplicated

func RemoveLineInFile

func RemoveLineInFile(filePath, startwith string, fullline bool) result.Result

RemoveLineInFile removes all the lines of filepath which are starting with startwith. if fullline == true, an exact match (instead of start with) is required to remove the line.

func StringFileContains

func StringFileContains(filePath string, content string) (bool, error)

StringFileContains checks if a content is already present inside a file. The content MUST be a FULL line (with strict line equality) or a set of full lines with a '\n' between them.

func SymlinkExists

func SymlinkExists(filePath string) (bool, error)

SymlinkExists checks if a symbolic link exists. Returns true if the file exists and is a symbolic link, false otherwise. error != nil if the file exists and is not a symbolic link (ie a directory). TODO : return value is a bit overcomplicated

func UpdateLineInFile

func UpdateLineInFile(filePath, startwith, replacement string, appendIfNoMatch bool) result.Result

UpdateLineInFile replaces all the lines of filepath which are starting with startwith by replacement. if appendIfNoMatch == true, appends the replacement at the end of the file if no replacement have been made before.

func UpdateOrCreateSymlink(existing, linkname string) result.Result

UpdateOrCreateSymlink

func WriteBinaryFile

func WriteBinaryFile(filePath string, newContent []byte, writeIfFileExists bool) result.Result

WriteBinaryFile creates a file and writes the content of a byte slice into it. if overwrite == true, replaces the file content if the file exists.

func WriteStringFile

func WriteStringFile(filePath, newContent string, overwrite bool) result.Result

WriteStringFile creates a file and writes the content of a string into it. if overwrite == true, replaces the file content if the file exists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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