Documentation ¶
Index ¶
- Constants
- func Abs(path string) string
- func ByteSize(path string) (int64, error)
- func Clean(path string)
- func Copy(source string, dest string, ignoreErrors ...bool) error
- func Exists(path string) bool
- func FormatSize(bytesize int64, sigfig ...int) string
- func IsDirectory(path string) bool
- func IsExecutable(path string) bool
- func IsFile(path string) bool
- func IsReadable(path string) bool
- func IsSymlink(path string) bool
- func IsWritable(path string) bool
- func LastModified(path string) (time.Time, error)
- func List(directory string, recursive bool, ignore ...string) ([]string, error)
- func ListDirectories(directory string, recursive bool, ignore ...string) ([]string, error)
- func ListFiles(directory string, recursive bool, ignore ...string) ([]string, error)
- func Mkdir(path string) string
- func Move(source string, dest string, ignoreErrors ...bool) error
- func ReadFile(path string) ([]byte, error)
- func ReadTextFile(path string) (string, error)
- func Size(path string, sigfig ...int) (string, error)
- func Symlink(target string, name string) error
- func Touch(path string, flags ...any) string
- func Unzip(src string, dest string) error
- func WriteFile(path string, content string) (int, error)
- func WriteTextFile(path string, content string, args ...any) error
- func Zip(src string, target ...string) error
Constants ¶
const ( // KB represents the size of a kilobyte. KB float64 = 1024 // MB represents the size of a megabyte. MB float64 = 1024 * KB // GB represents the size of a gigabyte. GB float64 = 1024 * MB // TB represents the size of a terabyte. TB float64 = 1024 * GB // PB represents the size of a petabyte. PB float64 = 1024 * TB )
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
Abs Returns the fully resolved path, even if the path does not exist.
``` fsx.Abs("./does/not/exist") ``` If the code above was run within `/home/user`, the result would be `/home/user/does/not/exist`.
func Clean ¶
func Clean(path string)
Clean will ensure the specified directory exists. If the directory already exists, all of contents are deleted. If the directory does not exist, it is automatically created.
func FormatSize ¶
FormatSize returns a nicely formatted representation of a number of bytes, such as `3.14MB`
func IsDirectory ¶
IsDirectory determines whether the specified path represents a directory.
func IsExecutable ¶
IsExecutable determines whether the file/directory is executable for the active system user.
func IsReadable ¶
IsReadable determines whether the file/directory is readable for the active system user.
func IsWritable ¶
IsWritable determines whether the file/directory is writable for the active system user.
func LastModified ¶
LastModified identies the last time the path was modified.
func List ¶
List Generate a list of path names for the given directory. Optionally provide a list of ignored paths, using [glob](https://en.wikipedia.org/wiki/Glob_%28programming%29) syntax.
func ListDirectories ¶
ListDirectories provides absolute paths of directories only, ignoring files.
func Mkdir ¶
Mkdir is the equivalent of [mkdir -p](https://en.wikipedia.org/wiki/Mkdir) It will generate the full directory path if it does not already exist.
func ReadTextFile ¶
ReadTextFile reads a text file and converts results from bytes to a string.
func Touch ¶
Touch Similar to the touch command on *nix, where the file or directory will be created if it does not already exist. Returns the absolute path. The optional second boolean argument will force the method to treat the path as a file instead of a directory (useful when the filename has no extension). An optional 3rd boolean argument will force the method to treat the path as a directory even if a file extension is present.
For example: `fsx.Touch("./path/to/archive.old", false, true)`
Normally, any file path with an extension is determined to be a file. However; the second argument (`false`) instructs the command to **not** force a file. The third argument (`true`) instructs the command to **treat the path like a directory**.
func WriteTextFile ¶
WriteTextFile writes text to a file (automatically converts string to a byte array). If the path does not exist, it will be created automatically. This is the equivalent of using the Touch() method first, then writing text content to the file.
It is also possible to pass a third argument, a custom permission. By default, os.ModePerm is used.
Types ¶
This section is empty.