renamer

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package renamer provides reusable, preview-first file rename and move operations.

Index

Constants

This section is empty.

Variables

View Source
var DefaultExtensionGroups = map[string][]string{
	"image": {"jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", "heic", "heif", "tif", "tiff", "ico", "eps", "psd", "raw", "cr2", "nef", "arw", "orf"},
	"text":  {"txt", "md", "rtf"}, "data": {"json", "ndjson", "csv", "tsv", "parquet", "orc", "avro", "db", "sqlite", "sql"},
	"video":    {"mp4", "avi", "mkv", "mov", "wmv", "flv", "webm", "3gp", "mts", "m2ts", "m4v"},
	"audio":    {"mp3", "wav", "flac", "m4a", "ogg", "aac", "opus"},
	"document": {"pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "odt", "ods", "pages", "key", "numbers"},
	"archive":  {"zip", "tar", "gz", "tgz", "rar", "7z", "xz", "bz2"},
	"code":     {"py", "js", "ts", "go", "java", "rb", "php", "html", "css", "c", "cpp", "h", "cs", "rs", "kt", "swift", "scala", "sh"},
	"font":     {"ttf", "otf", "woff", "woff2"}, "ebook": {"epub", "mobi"}, "logs": {"log"},
}
View Source
var DefaultGroupFolderNames = map[string]string{
	"image": "Images", "text": "Text", "data": "Data", "video": "Videos", "audio": "Audio",
	"document": "Documents", "archive": "Archives", "code": "Code", "font": "Fonts", "ebook": "Ebooks", "logs": "Logs",
}

Functions

func ApplyRule

func ApplyRule(rule Rule, filePath string, groups map[string][]string, counter int) (string, error)

func MergeExtensionGroups

func MergeExtensionGroups(user map[string][]string) map[string][]string

func WriteOperations

func WriteOperations(w io.Writer, operations []Operation) error

Types

type Category

type Category struct {
	Name       string   `json:"name"`
	Extensions []string `json:"extensions,omitempty"`
	Patterns   []string `json:"patterns,omitempty"`
	TargetDir  string   `json:"target_dir"`
}

type Config

type Config struct {
	Rules           []Rule              `json:"rules"`
	Categories      []Category          `json:"categories,omitempty"`
	ExtensionGroups map[string][]string `json:"extension_groups,omitempty"`
	GroupFolders    map[string]string   `json:"group_folders,omitempty"`
}

func LoadConfig

func LoadConfig(filename string) (*Config, error)

type DateFormat

type DateFormat struct {
	Input  string `json:"input"`
	Output string `json:"output"`
}

type Operation

type Operation struct {
	Action string `json:"action"`
	From   string `json:"from"`
	To     string `json:"to"`
	Status string `json:"status"`
	Error  string `json:"error,omitempty"`
}

Operation describes either a planned or completed filesystem change.

func Categorize

func Categorize(targetDir string, categories []Category, groups map[string][]string, dryRun bool) ([]Operation, error)

Categorize moves files matching category extensions or regular expressions.

func Group

func Group(targetDir string, groups map[string][]string, folders map[string]string, dryRun bool) ([]Operation, error)

Group moves files below targetDir into extension-group folders.

func Move

func Move(src, dst string, dryRun bool) Operation

Move renames a file or directory to dst. It never overwrites an existing path.

func Rename

func Rename(rule Rule, targetDir string, dryRun bool, groups map[string][]string) ([]Operation, error)

Rename applies one rule to matching files. Dry-run operations have status "planned".

type RenameRule

type RenameRule = Rule

RenameRule is retained as a descriptive alias for callers loading configs.

type Rule

type Rule struct {
	Name        string     `json:"name"`
	Pattern     string     `json:"pattern"`
	Replacement string     `json:"replacement"`
	Type        string     `json:"type"`
	Priority    int        `json:"priority,omitempty"`
	DateFormat  DateFormat `json:"date_format,omitempty"`
	Recursive   bool       `json:"recursive"`
	FileTypes   []string   `json:"file_types,omitempty"`
}

Jump to

Keyboard shortcuts

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