Documentation
¶
Overview ¶
fsutil/directory.go
fsutil/files.go
fsutil/locations.go
fsutil/paths.go
fsutil/permissions.go
Index ¶
- func AppendStringToFile(path string, content string) error
- func AppendToFile(path string, data []byte) error
- func CleanDir(path string) error
- func CleanPath(path string) string
- func ConvertToOSPath(path string) string
- func CopyDir(src, dst string) error
- func CopyDirContents(src, dst string) error
- func CopyFile(src, dst string) error
- func CopySymlink(src, dst string) error
- func CreateDir(path string, perm os.FileMode) error
- func CreateDirIfNotExists(path string) error
- func CreateTempDir(prefix string) (string, error)
- func CreateTempDirIn(dir, prefix string) (string, error)
- func DeleteDir(path string) error
- func DeleteDirRecursive(path string) error
- func DeleteFile(path string) error
- func DirExists(path string) bool
- func EnsureEmptyDir(path string) error
- func ExpandTilde(path string) (string, error)
- func FileExists(path string) bool
- func FindFiles(root, pattern string) ([]string, error)
- func FindFilesByExt(root, ext string) ([]string, error)
- func GetCacheDir(appName string) (string, error)
- func GetConfigDir(appName string) (string, error)
- func GetDataDir(appName string) (string, error)
- func GetDir(path string) string
- func GetDirSize(path string) (int64, error)
- func GetExecutableDir() (string, error)
- func GetExtension(path string) string
- func GetFileAttributes(path string) (string, error)
- func GetFileHash(path string, hashType string) (string, error)
- func GetFileNameWithoutExt(path string) string
- func GetFreeDiskSpace(path string) (uint64, error)
- func GetGroup(path string) (string, error)
- func GetHomeDir() (string, error)
- func GetLogDir(appName string) (string, error)
- func GetOwner(path string) (string, error)
- func GetPathDepth(path string) int
- func GetPathMutex(path string) *sync.Mutex
- func GetPermissions(path string) (os.FileMode, error)
- func GetRuntimeDir(appName string) (string, error)
- func GetSystemConfigDir(appName string) (string, error)
- func GetSystemDataDir(appName string) (string, error)
- func GetSystemLogDir(appName string) (string, error)
- func GetTempCompressionDir() (string, error)
- func GetTempDir(appName string) (string, error)
- func GetWorkingDir() (string, error)
- func HasEnoughDiskSpace(path string, requiredBytes uint64) (bool, error)
- func IsAbsPath(path string) bool
- func IsDirEmpty(path string) (bool, error)
- func IsExecutable(path string) bool
- func IsFileBinary(path string) (bool, error)
- func IsFileEmpty(path string) (bool, error)
- func IsFileExecutable(path string) bool
- func IsHidden(path string) (bool, error)
- func IsReadable(path string) bool
- func IsSymlink(path string) (bool, error)
- func IsSymlinkTo(path, target string) (bool, error)
- func IsUnixPath(path string) bool
- func IsWindowsPath(path string) bool
- func IsWritable(path string) bool
- func JoinPath(elem ...string) string
- func MakeHidden(path string) error
- func MakeReadOnly(path string) error
- func MakeWritable(path string) error
- func MoveDir(src, dst string) error
- func MoveFile(src, dst string) error
- func NormalizePath(path string) string
- func PathSeparator() string
- func ReadFile(path string) ([]byte, error)
- func ReadFileChunked(path string, chunkSize int, processChunk func([]byte) error) error
- func ReadFileChunkedWithLimit(path string, chunkSize int, maxBytes int64, ...) error
- func ReadFileHeader(path string, n int) ([]byte, error)
- func ReadFileString(path string) (string, error)
- func ReadLines(path string) ([]string, error)
- func RelativePath(basePath, targetPath string) (string, error)
- func SetFileExecutable(path string, executable bool) error
- func SetGroup(path string, groupname string) error
- func SetOwner(path string, username string) error
- func SetPermissions(path string, mode os.FileMode) error
- func SetRecursivePermissions(path string, dirMode, fileMode os.FileMode) error
- func SetWindowsAttributes(path string, attrs WindowsFileAttributes) error
- func SplitPath(path string) (dir, file string)
- func ToAbsPath(path string) (string, error)
- func TouchFile(path string) error
- func WalkDir(root string, fn func(path string, info fs.FileInfo, err error) error) error
- func WriteFile(path string, data []byte, perm os.FileMode) error
- func WriteFileString(path string, content string, perm os.FileMode) error
- type DirEntry
- type FileInfo
- type PermissionMode
- type WindowsFileAttributes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendStringToFile ¶
AppendStringToFile appends a string to an existing file
func AppendToFile ¶
AppendToFile appends data to an existing file
func CleanDir ¶
CleanDir removes all contents from a directory without removing the directory itself
func CleanPath ¶
CleanPath cleans a path by removing redundant separators and resolving ".." and "."
func ConvertToOSPath ¶
ConvertToOSPath converts a path to use the current OS path format
func CopyDirContents ¶
CopyDirContents copies the contents of a directory without recreating the source directory
func CopySymlink ¶
CopySymlink copies a symlink from source to destination
func CreateDirIfNotExists ¶
CreateDirIfNotExists creates a directory with standard permissions if it doesn't exist
func CreateTempDir ¶
CreateTempDir creates a temporary directory with a prefix
func CreateTempDirIn ¶
CreateTempDirIn creates a temporary directory with a prefix in a specific directory
func DeleteDirRecursive ¶
DeleteDirRecursive removes a directory and all its contents
func EnsureEmptyDir ¶
EnsureEmptyDir ensures a directory exists and is empty
func ExpandTilde ¶
ExpandTilde expands the tilde in paths to the user's home directory
func FileExists ¶
FileExists checks if a file exists and is not a directory
func FindFilesByExt ¶
FindFilesByExt finds all files with a specific extension in a directory (recursive)
func GetCacheDir ¶
GetCacheDir returns the appropriate cache directory for the application
func GetConfigDir ¶
GetConfigDir returns the appropriate configuration directory for the application
func GetDataDir ¶
GetDataDir returns the appropriate data directory for the application
func GetDir ¶
GetDir returns the directory of a given file path This is a pure path operation that doesn't access the filesystem, so no locking needed
func GetDirSize ¶
GetDirSize calculates the total size of a directory and its contents
func GetExecutableDir ¶
GetExecutableDir returns the directory of the current executable
func GetExtension ¶
GetExtension returns the file extension with the dot (e.g., ".txt")
func GetFileAttributes ¶
GetFileAttributes gets platform-specific file attributes
func GetFileHash ¶
GetFileHash calculates a file's hash using the specified algorithm
func GetFileNameWithoutExt ¶
GetFileNameWithoutExt returns the file name without its extension
func GetFreeDiskSpace ¶
GetFreeDiskSpace returns the available disk space in bytes for a given path
func GetPathDepth ¶
GetPathDepth returns the number of path components (levels of depth)
func GetPathMutex ¶
GetPathMutex returns a mutex for the given path
func GetPermissions ¶
GetPermissions retrieves the permissions of a file or directory
func GetRuntimeDir ¶
GetRuntimeDir returns a directory for runtime files (sockets, PIDs, etc.)
func GetSystemConfigDir ¶
GetSystemConfigDir returns the system-wide configuration directory
func GetSystemDataDir ¶
GetSystemDataDir returns the system-wide data directory
func GetSystemLogDir ¶
GetSystemLogDir returns the system-wide log directory
func GetTempCompressionDir ¶
GetTempCompressionDir returns a temporary directory for compression/extraction operations
func GetTempDir ¶
GetTempDir returns a temporary directory for the application
func GetWorkingDir ¶
GetWorkingDir returns the current working directory
func HasEnoughDiskSpace ¶
HasEnoughDiskSpace checks if there is sufficient free space for a file operation
func IsDirEmpty ¶
IsDirEmpty checks if a directory is empty
func IsExecutable ¶
IsExecutable checks if a file is executable by the current user
func IsFileBinary ¶
IsFileBinary makes a best-effort determination of whether a file is binary or text
func IsFileEmpty ¶
IsFileEmpty checks if a file is empty (size of 0 bytes)
func IsFileExecutable ¶
IsFileExecutable checks if a file is executable
func IsReadable ¶
IsReadable checks if a file or directory is readable by the current user
func IsSymlinkTo ¶
IsSymlinkTo checks if a path is a symlink pointing to a specific target
func IsUnixPath ¶
IsUnixPath checks if a path appears to be a Unix-style path
func IsWindowsPath ¶
IsWindowsPath checks if a path appears to be a Windows-style path
func IsWritable ¶
IsWritable checks if a file or directory is writable by the current user
func MakeReadOnly ¶
MakeReadOnly makes a file or directory read-only
func MakeWritable ¶
MakeWritable makes a file or directory writable
func NormalizePath ¶
NormalizePath normalizes a path for the current OS This is particularly useful when dealing with paths that might have been created on a different OS
func PathSeparator ¶
func PathSeparator() string
PathSeparator returns the OS-specific path separator character
func ReadFileChunked ¶
ReadFileChunked reads a file in chunks, calling the provided function for each chunk
func ReadFileChunkedWithLimit ¶
func ReadFileChunkedWithLimit(path string, chunkSize int, maxBytes int64, processChunk func([]byte, int64) error) error
ReadFileChunkedWithLimit reads a file in chunks, stopping after maxBytes or EOF
func ReadFileHeader ¶
ReadFileHeader reads the first n bytes of a file
func ReadFileString ¶
ReadFileString reads a file and returns its contents as a string
func RelativePath ¶
RelativePath returns a relative path from base to target
func SetFileExecutable ¶
SetFileExecutable sets or removes the executable bit on a file
func SetPermissions ¶
SetPermissions sets the permissions of a file or directory
func SetRecursivePermissions ¶
SetRecursivePermissions sets permissions recursively on a directory
func SetWindowsAttributes ¶
func SetWindowsAttributes(path string, attrs WindowsFileAttributes) error
SetWindowsAttributes sets Windows-specific file attributes
func TouchFile ¶
TouchFile updates a file's access and modification times, creating it if it doesn't exist
Types ¶
type DirEntry ¶
type DirEntry struct { Path string Name string IsDir bool Size int64 Mode os.FileMode ModTime time.Time FullPath string }
DirEntry represents an entry in a directory (file or subdirectory)
func GetNewestFile ¶
GetNewestFile finds the most recently modified file in a directory (non-recursive)
func GetOldestFile ¶
GetOldestFile finds the oldest file in a directory (non-recursive)
type FileInfo ¶
type FileInfo struct { Path string Size int64 Mode os.FileMode IsDir bool ModTime time.Time ContentType string }
FileInfo represents metadata about a file
func GetFileInfo ¶
GetFileInfo retrieves file information
type PermissionMode ¶
type PermissionMode uint32
PermissionMode represents a file permission mode
const ( PermUserRead PermissionMode = 0400 PermUserWrite PermissionMode = 0200 PermUserExec PermissionMode = 0100 PermUserRWX PermissionMode = 0700 PermGroupRead PermissionMode = 0040 PermGroupWrite PermissionMode = 0020 PermGroupExec PermissionMode = 0010 PermGroupRWX PermissionMode = 0070 PermOtherRead PermissionMode = 0004 PermOtherWrite PermissionMode = 0002 PermOtherExec PermissionMode = 0001 PermOtherRWX PermissionMode = 0007 PermAllRead PermissionMode = 0444 PermAllWrite PermissionMode = 0222 PermAllExec PermissionMode = 0111 PermAllRWX PermissionMode = 0777 PermStandard PermissionMode = 0644 PermStdExec PermissionMode = 0755 PermDirectory PermissionMode = 0755 )
Permission constants
type WindowsFileAttributes ¶
type WindowsFileAttributes uint32
WindowsFileAttributes represents common Windows file attributes
const ( WinAttrReadOnly WindowsFileAttributes = 0x1 WinAttrHidden WindowsFileAttributes = 0x2 WinAttrSystem WindowsFileAttributes = 0x4 WinAttrDirectory WindowsFileAttributes = 0x10 WinAttrArchive WindowsFileAttributes = 0x20 WinAttrNormal WindowsFileAttributes = 0x80 )
Windows attribute constants - defined with their actual values even though we won't use golang.org/x/sys/windows
func GetWindowsAttributes ¶
func GetWindowsAttributes(path string) (WindowsFileAttributes, error)
GetWindowsAttributes returns Windows-specific file attributes as a uint32