Documentation
¶
Overview ¶
Package renamer provides reusable, preview-first file rename and move operations.
Index ¶
- Variables
- func ApplyRule(rule Rule, filePath string, groups map[string][]string, counter int) (string, error)
- func MergeExtensionGroups(user map[string][]string) map[string][]string
- func WriteOperations(w io.Writer, operations []Operation) error
- type Category
- type Config
- type DateFormat
- type Operation
- func Categorize(targetDir string, categories []Category, groups map[string][]string, ...) ([]Operation, error)
- func Group(targetDir string, groups map[string][]string, folders map[string]string, ...) ([]Operation, error)
- func Move(src, dst string, dryRun bool) Operation
- func Rename(rule Rule, targetDir string, dryRun bool, groups map[string][]string) ([]Operation, error)
- type RenameRule
- type Rule
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 ¶
Types ¶
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 ¶
type DateFormat ¶
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.
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"`
}
Click to show internal directories.
Click to hide internal directories.