fs

package
v0.45.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 22 Imported by: 10

Documentation

Overview

Package fs contains helper functions to deal with files and folders.

Index

Constants

This section is empty.

Variables

View Source
var UnicodeNonStandardSpaces = []string{"\u00a0", "\u1680", "\u180e", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200a", "\u200b", "\u200c", "\u200d", "\u200e", "\u200f", "\u2063", "\u2028", "\u2029", "\u202a", "\u202b", "\u202c", "\u202d", "\u202e", "\u202f", "\u205f", "\u2060", "\u2061", "\u2062", "\u2063", "\u2064", "\u3000", "\ufeff"}

Functions

func AbsoluteFileExists

func AbsoluteFileExists(path string) (res bool)

AbsoluteFileExists checks if an absolute path is an existing file.

func ApplyCommands added in v0.16.0

func ApplyCommands(cmds []*exec.Cmd, title string, verbose bool) error

ApplyCommands using goroutines. Can be applied to files.

func CalculateMD5 added in v0.23.0

func CalculateMD5(filename string) (string, error)

CalculateMD5 calculates a file's current md5 hash.

func CalculateMD5First4KB

func CalculateMD5First4KB(path string) string

CalculateMD5First4KB calculates the MD5 of the beginning of a file.

func CalculateSHA256

func CalculateSHA256(filename string) (string, error)

CalculateSHA256 calculates a file's current sh&256 hash.

func ContainsNonStandardSpace added in v0.42.0

func ContainsNonStandardSpace(s string) bool

func CopyDir

func CopyDir(src, dst string, useHardLinks bool) error

CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist. Symlinks are ignored and skipped.

func CopyFile

func CopyFile(src, dst string, useHardLinks bool) (err error)

CopyFile copies a fs from src to dst. If src and dst files exist, and are the same, then return success. Copy the fs contents from src to dst.

func DeleteEmptyDirs

func DeleteEmptyDirs(root string, whitelist []string) error

DeleteEmptyDirs recursively deletes empty folders in a given path.

func DirExists

func DirExists(path string) bool

DirExists checks if a directory exists.

func DirIsEmpty

func DirIsEmpty(path string) (bool, error)

DirIsEmpty checks if a directory is empty.

func DownloadFile

func DownloadFile(filepath string, url string) error

DownloadFile will download a url to a local file. It will write as it downloads and not load the whole file into memory.

func FileExists

func FileExists(path string) bool

FileExists checks if a path is valid.

func FileSize

func FileSize(a uint64) string

func FileSizeDelta

func FileSizeDelta(a int64) string

func GetAllowedFilesByExt added in v0.25.0

func GetAllowedFilesByExt(directoryPath string, extensionWhitelist []string) []string

GetAllowedFilesByExt returns all files found in a directory with an extension that is whitelisted.

func GetExceedinglyLongPaths added in v0.19.7

func GetExceedinglyLongPaths(dir string, maxSize int) []string

GetExceedinglyLongPaths returns paths longer that maxSize inside of a root directory.

func GetFilesAndFoldersByPrefix added in v0.25.0

func GetFilesAndFoldersByPrefix(directoryPath string, prefixWhitelist []string) []string

GetFilesAndFoldersByPrefix returns all files and folders found in a directory with specific prefixes.

func GetFilesAndFoldersBySubstring added in v0.25.0

func GetFilesAndFoldersBySubstring(directoryPath string, prefixWhitelist []string) []string

GetFilesAndFoldersBySubstring returns all files and folders found in a directory with specific substrings.

func GetFilesByExt added in v0.3.0

func GetFilesByExt(directoryPath, extension string) ([]string, error)

GetFilesByExt returns all files found in a directory with a specific extension.

func GetForbiddenFilesByExt added in v0.25.0

func GetForbiddenFilesByExt(directoryPath string, extensionWhitelist []string) []string

GetForbiddenFilesByExt returns all files found in a directory with an extension that isn't whitelisted.

func GetMaxPathLength added in v0.17.0

func GetMaxPathLength(dir string) int

GetMaxPathLength inside a directory, including the name of the directory itself.

func GetPartialSize added in v0.25.0

func GetPartialSize(directoryPath string, whitelisted []string) int

GetPartialSize returns the size of some of the contents in a folder.

func GetPathsWithNonStandardSpaces added in v0.42.0

func GetPathsWithNonStandardSpaces(dir string) []string

func GetTopLevelSubDirectories added in v0.30.0

func GetTopLevelSubDirectories(root string) ([]string, error)

func GetTotalSize added in v0.25.0

func GetTotalSize(directoryPath string) int

GetTotalSize returns the size of a folder.

func GetUniqueFolder added in v0.20.0

func GetUniqueFolder(basePath string) (string, error)

GetUniqueFolder in a target directory, append indices if folder already exists.

func GetUniqueTimestampedFilename

func GetUniqueTimestampedFilename(dir, filename, extension string) (string, error)

GetUniqueTimestampedFilename for a given filename.

func HasEmptyNestedFolders added in v0.25.0

func HasEmptyNestedFolders(dir string) bool

GetEmptyNestedFolders returns true if it contains empty dirs, or dirs that only contain other dirs.

func MoveDir added in v0.5.0

func MoveDir(current, new string, doNothing, interactive bool) (bool, error)

MoveDir moves a directory to its new home.

func ResizeJPGIfNecessary added in v0.23.0

func ResizeJPGIfNecessary(image string, maxSizeKb int) (string, bool, error)

ResizeJPGIfNecessary and return the path to the acceptable image, and whether it is the original or a resized version.

func SanitizePath

func SanitizePath(path string) string

SanitizePath to have an acceptable path.

func Sign added in v0.2.0

func Sign(a int64) string

Types

type ByteSize

type ByteSize float64
const (
	KiB ByteSize = 1 << (10 * iota)
	MiB
	GiB
	TiB
)

func (ByteSize) String

func (b ByteSize) String() string

Jump to

Keyboard shortcuts

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