folder

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package folder provides a typed abstraction over filesystem directory paths. It offers utilities for path manipulation, creation, listing, and file search.

Index

Constants

This section is empty.

Variables

View Source
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

type CriteriaFunc func(file.File) (bool, error)

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

func CreateRandomInDir(dir, pattern string) (Folder, error)

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

func FromFile(f file.File) Folder

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

func New(paths ...string) Folder

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

func NewInTempDir(paths ...string) Folder

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) AsFile

func (f Folder) AsFile() file.File

AsFile converts the folder path to a File type.

func (Folder) Base

func (f Folder) Base() string

Base returns the last component of the folder path.

func (Folder) Create

func (f Folder) Create() error

Create ensures the directory and its parents exist. Creates all necessary directories with 0755 permissions.

func (Folder) Dir added in v0.1.11

func (f Folder) Dir() Folder

Dir returns the parent directory of this folder.

func (Folder) Exists

func (f Folder) Exists() bool

Exists checks if the directory exists in the filesystem.

func (Folder) Expanded

func (f Folder) Expanded() Folder

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, with the shortest path. Returns ErrNotFound if no file matches all criteria.

func (Folder) FindFiles added in v0.1.5

func (f Folder) FindFiles(criteria ...CriteriaFunc) (files.Files, error)

FindFiles searches for files matching all given criteria. Recursively searches the directory tree and returns all matching files. Returns an empty slice if no files match all criteria.

func (Folder) Info added in v0.0.13

func (f Folder) Info() (fs.FileInfo, error)

Info retrieves the file information for the directory.

func (Folder) IsSet

func (f Folder) IsSet() bool

IsSet checks if the folder path is non-empty.

func (Folder) Join

func (f Folder) Join(paths ...string) Folder

Join combines this path with additional components. Returns a new Folder with the combined path.

func (Folder) ListFiles

func (f Folder) ListFiles() (files files.Files, err error)

ListFiles returns all immediate regular files in the folder. It excludes directories and other non-file entries.

func (Folder) ListFolders

func (f Folder) ListFolders() (folders []Folder, err error)

ListFolders returns all immediate subdirectories of the folder. It excludes files and other non-directory entries.

func (Folder) Path

func (f Folder) Path() string

Path returns the string representation of the folder path.

func (Folder) RelativeTo

func (f Folder) RelativeTo(base Folder) (Folder, error)

RelativeTo returns the path from base to this folder. Returns an error if it can't be computed.

func (Folder) Remove

func (f Folder) Remove() error

Remove recursively deletes the directory and its contents.

func (Folder) Size added in v0.1.0

func (f Folder) Size() (int64, error)

Size returns the size of the folder in bytes.

func (Folder) String

func (f Folder) String() string

String returns the folder path as a string.

func (Folder) WithFile

func (f Folder) WithFile(path string) file.File

WithFile creates a File path within this directory. Combines the directory path with the provided filename.

Jump to

Keyboard shortcuts

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