filesystem

package module
v0.0.0-...-27496b3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: MIT Imports: 11 Imported by: 3

README

Filesystem

Filesystem is a package which allow users to perform high-level disk operations simply and easily. This package was created in an attempt to eliminate all the annoying code associated with file system calls (which inevitably end up being duplicated between projects anyway).

Features

  • A wide variety of common filesystem operations are available!
  • All methods are abstracted out to be as simple to use as possible!
  • All methods are obviously labeled, straight forward, and as self-explanatory as possible!
  • No need to remember/learn yet another set of basic filesystem calls for a new language!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendLineToFile

func AppendLineToFile(fileName string, lineToWrite string, permissions int) error

* AppendLineToFile allows you to append a line to the end of a file. In addition, the following information should be noted:

- In the event the file does not already exist, it will be created for you with the permission attributes provided.

- If you pass in a permissions value of '0', the default value of 666 will be used instead.

func CopyFile

func CopyFile(sourceFile string, destinationFile string) error

* CopyFile allows you to copy a file from one source location to a target destination location. In the event the operation could not be completed, an error is returned to the user.

func CreateDirectory

func CreateDirectory(directoryPath string, permissions uint32) error

* CreateDirectory allows you to create a directory on your local file system.

func DeleteDirectory

func DeleteDirectory(pathName string) error

DeleteDirectory allows you to recursively remove a directory from the file system.

func DeleteFile

func DeleteFile(fileName string) error

* DeleteFile allows you to delete a file on the file system.

func DeleteFilesMatchingPattern

func DeleteFilesMatchingPattern(fileName string) error

* DeleteFilesMatchingPattern allows you to delete files matching a specific pattern. Pattern syntax is the same as the 'Match' command.

func DownloadFile

func DownloadFile(url string, filepath string, header http.Header) error

* DownloadFile allows you to download a file from the internet to your local file system.

func FindMatchingContent

func FindMatchingContent(directoryPath string, regexMatchers []string, isFilesIncluded bool, isDirectoriesIncluded bool, isRecursive bool) ([]string, error)

* FindMatchingContent allows you to find matching content from a given directory path. Both shallow and recursive searches are supported and results are returned as a fully qualified path.

func FindReplaceInFile

func FindReplaceInFile(filename string, regexMatcher string, replacementValue string) error

FindReplaceInFile allows you to find and replace text from within a file. Since this method loads the entire contents of a file into memory, it should only be used for smaller files.

func GetBareDirectoryPath

func GetBareDirectoryPath(directoryPath string) string

GetBareDirectoryPath allows you to get a directory path without a trailing slash. This is useful for functions which explicitly need directories formatted this way.

func GetBaseDirectory

func GetBaseDirectory(filePath string) string

* GetBaseDirectory allows you to extract the directory from a file path.

func GetBaseFileName

func GetBaseFileName(fileName string) string

* GetBaseFileName allows you to extract the base name of a file without any path or file extensions.

func GetCurrentDirectory

func GetCurrentDirectory(directoryPath string) string

GetCurrentDirectory allows you to obtain the current directory from a fully qualified directory path.

func GetDefaultCacheDirectory

func GetDefaultCacheDirectory() (string, error)

GetDefaultCacheDirectory allows you to obtain the cache directory of a user. The cache directory is useful for storing program data that needs to be accessed frequently, but is not terribly important in case it has to be regenerated.

func GetFileContents

func GetFileContents(fileName string) ([]byte, error)

GetFileContents allows you to get the entire contents of a file.

func GetFileContentsAsBytes

func GetFileContentsAsBytes(fileName string) ([]byte, error)

* GetFileContentsAsBytes allows you to get the contents of a file as a byte array.

func GetFileExtension

func GetFileExtension(fileName string) string

* GetFileExtension allows you to get the file extension of a file.

func GetFileInstance

func GetFileInstance() fileInstanceType

GetFileInstance allows you to obtain a file instance to work on.

func GetFileNameFromPath

func GetFileNameFromPath(fullyQualifiedFileName string) string

* GetFileNameFromPath allows you to extract a file name from a fully qualified file path.

func GetFileSize

func GetFileSize(fileName string) (int64, error)

* GetFileSize allows you to obtain the size of a specified file in bytes.

func GetListOfDirectories

func GetListOfDirectories(directoryPath string, regexMatcher string) ([]string, error)

* GetListOfDirectories allows you to obtain a list of files that match a given regular expression.

func GetListOfDirectoryContents

func GetListOfDirectoryContents(directoryPath string, regexMatchers []string, isFilesIncluded bool, isDirectoriesIncluded bool) ([]string, error)

* GetListOfDirectoryContents allows you to obtain a list of files and directories that match a given regular expression.

func GetListOfFiles

func GetListOfFiles(directoryPath string, regexMatcher string) ([]string, error)

* GetListOfFiles allows you to obtain a list of files that match a given regular expression.

func GetNormalizedDirectoryPath

func GetNormalizedDirectoryPath(directoryPath string) string

* GetNormalizedDirectoryPath allows you to guarantee that a directory path is always formatted with a trailing slash at the end. This is useful when you need to work with paths in predictable and consistent manner.

func GetParentDirectory

func GetParentDirectory(fileOrDirectoryPath string) string

* GetParentDirectory allows you to obtain the container directory of your provided path. This will be everything except the last element of your path.

func GetWorkingDirectory

func GetWorkingDirectory() (string, error)

* GetWorkingDirectory allows you to obtain the current working directory where your program is executing.

func IsDirectory

func IsDirectory(directoryPath string) bool

IsDirectory allows you to check if a disk entry is a directory or not.

func IsDirectoryEmpty

func IsDirectoryEmpty(directoryName string) (bool, error)

* IsDirectoryEmpty allows you to detect if a directory is empty or not.

func IsDirectoryExists

func IsDirectoryExists(directoryPath string) bool

* IsDirectoryExists allows you to check if a directory exists or not on the file system.

func IsFile

func IsFile(path string) (bool, error)

* IsFile allows you to check if an item on the file system is a file or not.

func IsFileContainsText

func IsFileContainsText(filename string, regexMatcher string) (bool, error)

IsFileContainsText allows you to check if a file contains a matching string or not. Since this method loads the entire contents of a file into memory, it should only be used for smaller files.

func IsFileExists

func IsFileExists(filePath string) bool

* IsFileExists allows you to check if a file exists or not on the file system.

func MoveFile

func MoveFile(sourceFile string, destinationFile string) error

* MoveFile allows you to move a file from one location to another. This method is an alias which simply performs a rename command, which is capable of doing the same action.

func RemoveFirstLineFromFile

func RemoveFirstLineFromFile(fileName string) error

RemoveFirstLineFromFile allows you to remove the first line from a file.

func RenameFile

func RenameFile(sourceFileName string, targetFileName string) error

* RenameFile allows you to rename a file on your local file system. In the event that a file with the same name already exists, it will be overwritten. Here we explicitly do the delete so we don't depend on the 'os.Rename' behaviour of overwriting files which may be environment dependant.

func WriteBytesToFile

func WriteBytesToFile(fileName string, bytesToWrite []byte, permissions int) error

* WriteBytesToFile allows you to write a series of bytes to a given file. In addition, the following information should be noted:

- In the event the file does not already exist, it will be created for you with the permission attributes provided.

- If you pass in a permissions value of '0', the default value of 666 will be used instead.

Types

This section is empty.

Jump to

Keyboard shortcuts

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