Documentation
¶
Overview ¶
Package folder provides a typed abstraction over filesystem directory paths. It offers utilities for path manipulation, creation, listing, and file search.
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) Exists() bool
- func (f Folder) Expanded() Folder
- func (f Folder) FindFile(criteria ...CriteriaFunc) (file.File, error)
- func (f Folder) Info() (fs.FileInfo, error)
- func (f Folder) IsSet() bool
- func (f Folder) Join(paths ...string) Folder
- func (f Folder) ListFiles() (files files.Files, err error)
- func (f Folder) ListFolders() (folders []Folder, err error)
- func (f Folder) Path() string
- func (f Folder) RelativeTo(base Folder) (Folder, error)
- func (f Folder) Remove() error
- func (f Folder) Size() (int64, 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.
func CreateRandomInDir ¶
CreateRandomInDir creates a uniquely named directory. Creates a directory with a random name inside the specified directory. Use empty string for directory 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. See `New` for details on path normalization. Note: This does not create the directory, only constructs the path.
func New ¶
New creates a Folder from one or more path components. Joins the paths using filepath.Join and normalizes the result to use forward slashes. Note: This does not create the directory, only constructs the path.
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) 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) Join ¶
Join combines this path with additional components. Returns a new Folder with the combined path.
func (Folder) ListFiles ¶
ListFiles returns all immediate regular files in the folder. It excludes directories and other non-file entries.
func (Folder) ListFolders ¶
ListFolders returns all immediate subdirectories of the folder. It excludes files and other non-directory entries.
func (Folder) RelativeTo ¶
RelativeTo returns the path from base to this folder. Returns an error if it can't be computed.