folderutil

package
v0.0.92 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 9 Imported by: 120

README

folderutil

The package contains various helpers to interact with folders

UserConfigDirOrDefault

UserConfigDirOrDefault returns the default root directory to use for user-specific configuration data. Users should create their own application-specific subdirectory within this one and use that.

On Unix systems, it returns $XDG_CONFIG_HOME as specified by https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.config. On Darwin, it returns $HOME/Library/Application Support. On Windows, it returns %AppData%. On Plan 9, it returns $home/lib.

If the location cannot be determined (for example, $HOME is not defined), then it will return given value as default.

Documentation

Index

Constants

View Source
const (
	UnixPathSeparator    = "/"
	WindowsPathSeparator = "\\"
)

Variables

View Source
var (
	// Separator evaluated at runtime
	Separator = string(os.PathSeparator)
	// Remove source directory after successful sync
	RemoveSourceDirAfterSync = true
)

Functions

func AppCacheDirOrDefault added in v0.0.58

func AppCacheDirOrDefault(defaultCacheDir string, toolName string) string

AppCacheDirOrDefault returns the user cache directory or defaultCacheDir in case of error

func AppConfigDirOrDefault added in v0.0.37

func AppConfigDirOrDefault(defaultAppConfigDir string, toolName string) string

AppConfigDirOrDefault returns the app config directory

func GetFiles

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

GetFiles within a folder

func HomeDirOrDefault

func HomeDirOrDefault(defaultDirectory string) string

HomeDirOrDefault tries to obtain the user's home directory and returns the default if it cannot be obtained.

func IsUnixOS

func IsUnixOS() bool

func IsWindowsOS

func IsWindowsOS() bool

func IsWritable added in v0.0.51

func IsWritable(path string) bool

IsWritable checks if a path is writable by attempting to create a temporary file. It caches writable paths to avoid unnecessary file operations.

func PrintStdDirs added in v0.0.58

func PrintStdDirs(toolName string)

Prints the standard directories for a tool

func SyncDirectory added in v0.0.41

func SyncDirectory(source, destination string) error

SyncDirectory sync all files and non-empty directories from source to destination folder optionally removes source directory and removes source

func UserConfigDirOrDefault added in v0.0.37

func UserConfigDirOrDefault(defaultConfigDir string) string

UserConfigDirOrDefault returns the user config directory or defaultConfigDir in case of error

Types

type PathInfo

type PathInfo struct {
	IsAbsolute         bool
	RootPath           string
	Parts              []string
	PartsWithSeparator []string
}

PathInfo about a folder

func NewPathInfo

func NewPathInfo(path string) (PathInfo, error)

NewPathInfo returns info about a given path

func (PathInfo) MeshWith

func (pathInfo PathInfo) MeshWith(anotherPath string) ([]string, error)

MeshWith combine all values from Path with another provided path

func (PathInfo) Paths

func (pathInfo PathInfo) Paths() ([]string, error)

Returns all possible combination of the various levels of the path parts

Jump to

Keyboard shortcuts

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