folder

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package file provides utilities for handling folder operations.

The `Folder` type is a string-based abstraction over a directory paths. The package includes methods for creating, removing, expanding, and checking the existence of directories, as well as manipulating paths.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("file not found")

ErrNotFound is returned when a file is not found during a search operation.

Functions

This section is empty.

Types

type CriteriaFunc

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

CriteriaFunc defines a function type for filtering files during search operations.

type Folder

type Folder string

Folder represents a file system directory as a string. It provides methods for working with directories, such as creating, removing, expanding paths, and checking existence.

func CreateRandomInDir

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

CreateRandomInDir creates a new random directory inside the given directory. Use "" to create a random directory in the default directory for temporary files.

func New

func New(paths ...string) Folder

New creates a new Folder object from the provided path segments by joining them.

func NewInTempDir

func NewInTempDir(paths ...string) Folder

NewInTempDir assigns but does not create a directory inside the system's temporary directory.

func (Folder) Base

func (f Folder) Base() string

Base returns the last element of the Folder's path.

func (Folder) Create

func (f Folder) Create() error

Create creates the Folder and all necessary parent directories with 0755 permissions.

func (Folder) CreateIgnoreExisting

func (f Folder) CreateIgnoreExisting() error

CreateIgnoreExisting creates the Folder and all necessary parent directories with 0755 permissions. If the directory already exists, the error is nil.

func (Folder) Exists

func (f Folder) Exists() bool

Exists checks if the Folder exists in the file system.

func (Folder) Expanded

func (f Folder) Expanded() Folder

Expanded expands the file path in case of ~ and returns the expanded path.

func (Folder) FindFile

func (f Folder) FindFile(criteria ...CriteriaFunc) (file.File, error)

FindFile searches for a file in the Folder that matches the provided criteria. It returns the first file found or an error if none are found.

func (Folder) IsParentOf

func (f Folder) IsParentOf(other Folder) bool

IsParentOf determines if the Folder is a parent directory of the given 'other' Folder.

func (Folder) IsSet

func (f Folder) IsSet() bool

IsSet checks whether the Folder has been set to a non-empty value.

func (Folder) ListFiles

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

ListFiles returns a slice of Files representing all files within the current Folder.

func (Folder) ListFolders

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

ListFolders returns a slice of Folders representing all subdirectories within the current Folder.

func (Folder) Normalized

func (f Folder) Normalized() Folder

Normalized converts the folder path to use forward slashes.

func (Folder) Path

func (f Folder) Path() string

Path returns the Folder path as a string.

func (Folder) Remove

func (f Folder) Remove() error

Remove deletes the Folder and all of its contents.

func (Folder) String

func (f Folder) String() string

String returns the Folder as a string.

Jump to

Keyboard shortcuts

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