Documentation
¶
Overview ¶
Package file provides utilities for handling folder and file operations.
The `File` type is a string-based abstraction over file paths that simplifies common file operations. Additionally, the package supports searching for files that meet specific criteria, handling file extensions, and working with collections of files through the `Files` type.
Index ¶
- type Extension
- type File
- func (f File) Base() string
- func (f *File) Chmod(mode fs.FileMode) error
- func (f File) Copy(other File) error
- func (f File) Create() error
- func (f File) Dir() string
- func (f File) Exists() bool
- func (f File) Expanded() File
- func (f File) Extension() Extension
- func (f File) IsDir() bool
- func (f File) IsExecutable() (bool, error)
- func (f File) IsFile() bool
- func (f File) Normalized() File
- func (f File) Open() (*os.File, error)
- func (f File) OpenForWriting() (*os.File, error)
- func (f File) Path() string
- func (f File) Remove() error
- func (f File) String() string
- func (f File) Symlink(symlinks ...File) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File string
File represents a file path as a string, providing methods for file operations.
func (File) Copy ¶
Copy copies the contents of the current file to the specified destination File. It returns an error if the operation fails.
func (File) Dir ¶
Dir returns the directory of the file. If the file is a directory, it returns the path of the directory itself.
func (File) Expanded ¶ added in v0.0.6
Expanded expands the file path in case of ~ and returns the expanded path.
func (File) Extension ¶
Extension returns the file extension of the File, mapped to a predefined Extension constant.
func (File) IsExecutable ¶
IsExecutable checks if the file has executable permissions.
func (File) Normalized ¶
Normalized converts the file path to use forward slashes.
func (File) Open ¶
Open opens the file for reading and returns a pointer to the os.File object, or an error. The user must close the file after use.
func (File) OpenForWriting ¶ added in v0.0.1
OpenForWriting opens the file for writing and returns a pointer to the os.File object. If the file doesn't exist, it will be created. If it exists, it will be truncated. The user must close the file after use.
func (File) Symlink ¶
Symlink creates symbolic links for the File to each of the provided symlink Files on Linux or Darwin systems. If a symlink already exists, it will skip that symlink and continue without returning an error. Returns an error if any symlink creation fails (excluding existing symlinks).