file

package
v0.0.10 Latest Latest
Warning

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

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

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extension

type Extension int

Extension represents a file extension type.

const (
	// None represents no file extension.
	None Extension = iota
	// EXE represents the ".exe" file extension.
	EXE
	// GZ represents the ".gz" file extension.
	GZ
	// ZIP represents the ".zip" file extension.
	ZIP
	// Other represents any other, unrecognized file extension.
	Other
)

type File

type File string

File represents a file path as a string, providing methods for file operations.

func New added in v0.0.9

func New(paths ...string) File

New creates a new File by joining the provided paths.

func (File) Base added in v0.0.6

func (f File) Base() string

Base returns the base name of the File.

func (*File) Chmod

func (f *File) Chmod(mode fs.FileMode) error

Chmod changes the file permissions to the specified fs.FileMode.

func (File) Copy

func (f File) Copy(other File) error

Copy copies the contents of the current file to the specified destination File. It returns an error if the operation fails.

func (File) Create

func (f File) Create() error

Create creates a new file.

func (File) Dir

func (f File) Dir() string

Dir returns the directory of the file. If the file is a directory, it returns the path of the directory itself.

func (File) Exists

func (f File) Exists() bool

Exists checks if the file exists in the file system.

func (File) Expanded added in v0.0.6

func (f File) Expanded() File

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

func (File) Extension

func (f File) Extension() Extension

Extension returns the file extension of the File, mapped to a predefined Extension constant.

func (File) IsDir

func (f File) IsDir() bool

IsDir checks if the path represents a directory.

func (File) IsExecutable

func (f File) IsExecutable() (bool, error)

IsExecutable checks if the file has executable permissions.

func (File) IsFile

func (f File) IsFile() bool

IsFile checks if the path is a regular file (not a directory or special file).

func (File) Normalized

func (f File) Normalized() File

Normalized converts the file path to use forward slashes.

func (File) Open

func (f File) Open() (*os.File, error)

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

func (f File) OpenForWriting() (*os.File, error)

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) Path added in v0.0.1

func (f File) Path() string

Path returns the path of the File.

func (File) Remove

func (f File) Remove() error

Remove deletes the file from the file system.

func (File) String

func (f File) String() string

String returns the string representation of the File.

func (f File) Symlink(symlinks ...File) error

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

Jump to

Keyboard shortcuts

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