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(filepath 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 Mkdirp(path string) string
- func Move(source string, dest string, ignoreErrors ...bool) 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 ...interface{}) string
- func Unzip(src string, dest string) error
- func WriteTextFile(path string, content string, args ...interface{}) error
- func Zip(src string, target ...string) error
Constants ¶
const GB float64 = 1024 * MB
GB represents the size of a giggabyte.
const KB float64 = 1024
KB represents the size of a kilobyte.
const MB float64 = 1024 * KB
MB represents the size of a megabyte.
const PB float64 = 1024 * TB
PB represents the size of a petabyte.
const TB float64 = 1024 * GB
TB represents the size of a terabyte.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
Returns the fully resolved path, even if the path does not exist.
``` fsutil.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 ¶ added in v1.0.8
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 ¶ added in v1.0.9
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 ¶ added in v1.0.8
LastModified identies the last time the path was modified.
func 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 Mkdirp ¶
Mkdirp 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 ¶
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 not 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: `fsutil.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.