filemanager

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B  = 1 << (10 * iota) // 1 << (10 * 1) = 1024
	KB = 1 << (10 * iota) // 1 << (10 * 2) = 1048576
	MB = 1 << (10 * iota) // 1 << (10 * 3) = 1073741824
	GB = 1 << (10 * iota) // 1 << (10 * 4) = 1099511627776
	TB = 1 << (10 * iota) // 1 << (10 * 5) = 1125899906842624
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileManager

type FileManager struct {
	// contains filtered or unexported fields
}

FileManager structure for managing file and directory content

func NewFileManager

func NewFileManager() *FileManager

NewFileManager creates a new instance of FileManager

func (*FileManager) DeleteFileIfExists

func (fm *FileManager) DeleteFileIfExists(filePath string) error

func (*FileManager) Has

func (fm *FileManager) Has(path string) (bool, error)

Has checks if a file or directory exists at the specified path

func (*FileManager) ListFilesInDirectory

func (fm *FileManager) ListFilesInDirectory(dir string, filterFunc func(entry os.DirEntry) bool) ([]os.FileInfo, error)

ListFilesInDirectory lists files and directories in a specified path

func (*FileManager) ListFilesRecursively

func (fm *FileManager) ListFilesRecursively(dir string) ([]os.FileInfo, error)

ListFilesRecursively lists all files and directories in a specified path recursively

func (*FileManager) ReadFile

func (fm *FileManager) ReadFile(filePath string, output interface{}) error

ReadFile retrieves file content in the specified format

func (*FileManager) ReadUserInput

func (fm *FileManager) ReadUserInput() (string, error)

ReadUserInput retrieves user input line by line

func (*FileManager) RemoveFileOrDirectory

func (fm *FileManager) RemoveFileOrDirectory(path string) error

RemoveFileOrDirectory deletes a file or directory

func (*FileManager) Rename

func (fm *FileManager) Rename(oldPath, newPath string) error

Rename changes the name of a file or directory

func (*FileManager) WriteFile

func (fm *FileManager) WriteFile(filePath string, content interface{}) error

WriteFile creates or updates a file with specified content in the given format

func (*FileManager) WriteFileWithFunc

func (fm *FileManager) WriteFileWithFunc(filePath string, contentFunc func() (interface{}, error)) error

type FileManagerInterface

type FileManagerInterface interface {
	ListFilesInDirectory(dir string) ([]os.FileInfo, error)
	ListFilesRecursively(dir string) ([]os.FileInfo, error)
	WriteFile(filePath string, content interface{}) error
	ReadFile(filePath string, output interface{}) error
	Has(path string) (bool, error)
	RemoveFileOrDirectory(path string) error
	Rename(oldPath, newPath string) error
	ReadUserInput() (string, error)
}

FileManagerInterface defines the methods for the FileManager

type FileType

type FileType int

FileType defines the type for specifying file content formats

const (
	Text FileType // 1
	JSON          // 2
	Byte          // 3
)

Enum for file content types

Jump to

Keyboard shortcuts

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