Documentation
¶
Overview ¶
Package fileutils provides useful, high-level file operations
Index ¶
- func Checksum(path string, algo enum.HashAlg) (string, error)
- func CopyDir(src, dst string) error
- func CopyFile(src, dst string) error
- func IsDir(dirname string) bool
- func IsFile(filename string) bool
- func ListFiles(directory string) (list []string, err error)
- func MoveFile(src, dst string) error
- func SanitizePath(s string) string
- func TempFileName(dir, pattern string) (string, error)
- func TouchFile(path string) error
- type FileEvent
- type FileWatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Checksum ¶ added in v0.4.0
Checksum calculates the checksum of a file using the specified hash algorithm. Supported algorithms are MD5, SHA1, SHA224, SHA256, SHA384, SHA512, SHA512_224, and SHA512_256.
func CopyFile ¶
CopyFile copies a file from source to dest, preserving mode. Any existing file will be overwritten.
func MoveFile ¶ added in v0.3.0
MoveFile moves a file from src to dst. If rename fails (e.g., cross-device move), it will fall back to copy+delete. It will create destination directories if they don't exist.
func SanitizePath ¶ added in v0.2.0
SanitizePath returns a sanitized version of the given path.
func TempFileName ¶ added in v0.2.0
TempFileName returns a new temporary file name in the directory dir. The filename is generated by taking pattern and adding a random string to the end. If pattern includes a "*", the random string replaces the last "*". If dir is the empty string, TempFileName uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFileName simultaneously will not choose the same file name.
Types ¶
type FileEvent ¶ added in v0.4.0
type FileEvent struct { Path string // path to the file or directory Type enum.EventType // type of event }
FileEvent represents a file system event
type FileWatcher ¶ added in v0.4.0
type FileWatcher struct {
// contains filtered or unexported fields
}
FileWatcher watches for file system events
func NewFileWatcher ¶ added in v0.4.0
func NewFileWatcher(path string, callback func(FileEvent)) (*FileWatcher, error)
NewFileWatcher creates a new file watcher for the specified path
func WatchRecursive ¶ added in v0.4.0
func WatchRecursive(dir string, callback func(FileEvent)) (*FileWatcher, error)
WatchRecursive watches a directory recursively
func (*FileWatcher) AddPath ¶ added in v0.4.0
func (fw *FileWatcher) AddPath(path string) error
AddPath adds a path to the watcher
func (*FileWatcher) Close ¶ added in v0.4.0
func (fw *FileWatcher) Close() error
Close stops watching and releases resources
func (*FileWatcher) RemovePath ¶ added in v0.4.0
func (fw *FileWatcher) RemovePath(path string) error
RemovePath removes a path from the watcher