fsx

package
v0.0.0-...-049dabb Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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

func Abs(path string) string

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 ByteSize

func ByteSize(path string) (int64, error)

ByteSize returns the number of bytes (size) of a file/directory.

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 Copy

func Copy(source string, dest string, ignoreErrors ...bool) error

Copy a file/directory

func Exists

func Exists(path string) bool

Exists is a helper method to quickly determine whether a directory or file exists.

func FormatSize

func FormatSize(bytesize int64, sigfig ...int) string

FormatSize returns a nicely formatted representation of a number of bytes, such as `3.14MB`

func IsDirectory

func IsDirectory(path string) bool

IsDirectory determines whether the specified path represents a directory.

func IsExecutable

func IsExecutable(path string) bool

IsExecutable determines whether the file/directory is executable for the active system user.

func IsFile

func IsFile(path string) bool

IsFile determines whether the specified path represents a file.

func IsReadable

func IsReadable(path string) bool

IsReadable determines whether the file/directory is readable for the active system user.

func IsSymlink(path string) bool

IsSymlink determines whether the path is a symbolic link.

func IsWritable

func IsWritable(path string) bool

IsWritable determines whether the file/directory is writable for the active system user.

func LastModified

func LastModified(path string) (time.Time, error)

LastModified identies the last time the path was modified.

func List

func List(directory string, recursive bool, ignore ...string) ([]string, error)

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

func ListDirectories(directory string, recursive bool, ignore ...string) ([]string, error)

ListDirectories provides absolute paths of directories only, ignoring files.

func ListFiles

func ListFiles(directory string, recursive bool, ignore ...string) ([]string, error)

ListFiles provides absolute paths of files only, ignoring directories.

func Mkdir

func Mkdir(path string) string

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 Move

func Move(source string, dest string, ignoreErrors ...bool) error

Move a file/directory to another location

func ReadFile

func ReadFile(path string) ([]byte, error)

func ReadTextFile

func ReadTextFile(path string) (string, error)

ReadTextFile reads a text file and converts results from bytes to a string.

func Size

func Size(path string, sigfig ...int) (string, error)

Size returns a "pretty" version of the size, such as "3.12MB"

func Symlink(target string, name string) error

Symlink creates a symbolic link. This just runs `os.Symlink()`.

func Touch

func Touch(path string, flags ...any) string

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 Unzip

func Unzip(src string, dest string) error

Unzip a file

func WriteFile

func WriteFile(path string, content string) (int, error)

func WriteTextFile

func WriteTextFile(path string, content string, args ...any) error

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.

func Zip

func Zip(src string, target ...string) error

Zip a file or directory. Does not follow symlinks.

Types

This section is empty.

Jump to

Keyboard shortcuts

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