Skip to content

CaroLe-prw/rname-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rname

English | 中文


English

Batch file renaming tool with dry-run preview and rollback support.

Installation

cargo install --path .

Usage

rname [OPTIONS] <COMMAND>

Global Options

Option Description
--dry-run Preview rename plan without executing
--log <FILE> Save operation log for rollback

Commands

prefix - Add prefix

rname prefix --text <PREFIX> <PATHS>...

# Example: add prefix to all files in a directory
rname --dry-run prefix --text "2024_" ./photos

seq - Sequential rename

rname seq [--start N] [--step N] [--pad N] <PATHS>...

# Example: rename to 001.jpg, 002.jpg, ...
rname --dry-run seq --start 1 --pad 3 ./images
Option Default Description
--start 1 Starting number
--step 1 Step increment
--pad none Zero-padding width

replace - Regex replace

rname replace --pattern <REGEX> --with <REPLACEMENT> [--flags <FLAGS>] <PATHS>...

# Example: replace spaces with underscores
rname --dry-run replace --pattern " " --with "_" ./*.txt

# Example: case-insensitive replace
rname --dry-run replace --pattern "IMG" --with "photo" --flags i ./photos
Flag Description
i Case insensitive
m Multi-line mode
s Dot matches newline
x Ignore whitespace

rollback - Undo operations

rname rollback --log <LOG_FILE>

# Example: execute with log, then rollback
rname --log ops.json prefix --text "test_" ./files
rname rollback --log ops.json

Features

  • Accepts directories, auto-expands to files within
  • Two-phase rename, safely handles cyclic dependencies (e.g., a→b, b→a)
  • Auto-rollback on failure
  • JSON log format for later rollback

License

MIT


中文

批量文件重命名工具,支持预览 (dry-run) 和回滚。

安装

cargo install --path .

使用

rname [OPTIONS] <COMMAND>

全局选项

选项 说明
--dry-run 仅预览重命名计划,不实际执行
--log <FILE> 保存操作日志,用于回滚

命令

prefix - 添加前缀

rname prefix --text <PREFIX> <PATHS>...

# 示例:为目录下所有文件添加前缀
rname --dry-run prefix --text "2024_" ./photos

seq - 序号重命名

rname seq [--start N] [--step N] [--pad N] <PATHS>...

# 示例:重命名为 001.jpg, 002.jpg, ...
rname --dry-run seq --start 1 --pad 3 ./images
选项 默认值 说明
--start 1 起始序号
--step 1 序号步进
--pad 数字补零宽度

replace - 正则替换

rname replace --pattern <REGEX> --with <REPLACEMENT> [--flags <FLAGS>] <PATHS>...

# 示例:将空格替换为下划线
rname --dry-run replace --pattern " " --with "_" ./*.txt

# 示例:不区分大小写替换
rname --dry-run replace --pattern "IMG" --with "photo" --flags i ./photos
flags 说明
i 忽略大小写
m 多行模式
s . 匹配换行
x 忽略空白

rollback - 回滚

rname rollback --log <LOG_FILE>

# 示例:先执行并记录日志,然后回滚
rname --log ops.json prefix --text "test_" ./files
rname rollback --log ops.json

特性

  • 支持传入目录,自动展开为目录下的文件
  • 两阶段重命名,安全处理循环依赖(如 a→b, b→a)
  • 操作失败时自动回滚已完成的部分
  • JSON 格式日志,支持事后回滚

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages