Documentation
¶
Overview ¶
Package folder provides utilities for directory operations. It offers a Folder type that abstracts directory path handling and provides methods for common directory operations like creation, removal, path expansion, and existence checking. The package complements the file package by focusing on directory-specific operations and path manipulations.
Index ¶
- Variables
- type CriteriaFunc
- type Folder
- func (f Folder) AsFile() file.File
- func (f Folder) Base() string
- func (f Folder) Create() error
- func (f Folder) CreateIgnoreExisting() error
- func (f Folder) Exists() bool
- func (f Folder) Expanded() Folder
- func (f Folder) FindFile(criteria ...CriteriaFunc) (file.File, error)
- func (f Folder) IsParentOf(other Folder) bool
- func (f Folder) IsSet() bool
- func (f Folder) Join(paths ...string) Folder
- func (f Folder) ListFiles() (files.Files, error)
- func (f Folder) ListFolders() ([]Folder, error)
- func (f Folder) Normalized() Folder
- func (f Folder) Path() string
- func (f Folder) RelativeTo(base Folder) (Folder, error)
- func (f Folder) Remove() error
- func (f Folder) String() string
- func (f Folder) WithFile(path string) file.File
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("file not found")
ErrNotFound indicates a file matching the search criteria was not found.
Functions ¶
This section is empty.
Types ¶
type CriteriaFunc ¶
CriteriaFunc defines a file matching predicate. Returns true if a file matches the criteria, false otherwise.
type Folder ¶
type Folder string
Folder represents a filesystem directory path. Provides methods for directory operations including creation removal, path manipulation, and file searching. Handles pathnormalization and expansion of special characters like ~.
func CreateRandomInDir ¶
CreateRandomInDir creates a uniquely named directory. Creates a directory with a random name inside the specified parent. Use empty string for parent to create in system temp directory. Pattern is used as a prefix for the random directory name.
func FromFile ¶
FromFile creates a Folder from a file's parent directory. Extracts the directory component from the given file path.
func New ¶
New creates a Folder from one or more path components. Joins the paths using filepath.Join and normalizes the result.
func NewInTempDir ¶
NewInTempDir creates a Folder path in the system temp directory. Combines the system temp directory with the provided path components. Note: This does not create the directory, only constructs the path.
func (Folder) Create ¶
Create ensures the directory and its parents exist. Creates all necessary directories with 0755 permissions.
func (Folder) CreateIgnoreExisting ¶
CreateIgnoreExisting ensures the directory exists. Creates the directory and any missing parent directories. Returns nil if the directory already exists.
func (Folder) Expanded ¶
Expanded resolves environment variables including ~ home directory references.
func (Folder) FindFile ¶
func (f Folder) FindFile(criteria ...CriteriaFunc) (file.File, error)
FindFile searches for a file matching all given criteria. Recursively searches the directory tree and returns the first matching file. Returns ErrNotFound if no file matches all criteria.
func (Folder) IsParentOf ¶
IsParentOf checks if this folder contains another folder. Returns true if the other folder's path starts with this folder's path.
func (Folder) Join ¶
Join combines this path with additional components. Returns a new Folder with the combined path.
func (Folder) ListFiles ¶
ListFiles returns all immediate file entries. Returns a Files collection containing all regular files, excluding directories and other filesystem objects.
func (Folder) ListFolders ¶
ListFolders returns all immediate subdirectories. Returns a slice of Folders for each directory entry, excluding regular files and other filesystem objects.
func (Folder) Normalized ¶
Normalized returns the path with forward slashes. Converts backslashes to forward slashes for consistency.
func (Folder) RelativeTo ¶
RelativeTo computes the relative path from this folder to a base path. Returns an error if the relative path cannot be computed.