/rnm

Batch rename files and folders, recursively. Written in Go.

Primary LanguageGoMIT LicenseMIT

rnm

travis

Batch rename files and folders.

Note that this project is a Go implementation of 75lb/renamer and most of the README contents are copied from the original repository.

Install

$ go get github.com/ryym/rnm/cmd/rnm

Usage

$ rnm [options] <files>

-f, --find <string>

The find string, or regular expression when --regex is set. If not set, the whole filename will be replaced.

-r, --replace <string>

The replace string. With --regex set, --replace can reference parenthesised substrings from --find with $1, $2, $3 etc. If omitted, defaults to a blank

-e, --regex

When set, --find is intepreted as a regular expression.

-d, --dry-run

Used for test runs. Set this to do everything but rename the file.

Don't forget to test your rename first using --dry-run!

Examples

Some real-world examples.

Windows users: the single-quotation marks used in the example commands below are for bash (Mac/Linux) users, please replace these with double-quotation marks on Windows.

Simple replace

$ rnm --find '[bad]' --replace '[good]' *
BeforeAfter
.
├── A poem [bad].txt
├── A story [bad].txt
            
.
├── A poem [good].txt
├── A story [good].txt
            

Strip out unwanted text

$ rnm --find 'Season 1 - ' *
BeforeAfter
.
├── Season 1 - Some crappy episode.mp4
├── Season 1 - Load of bollocks.mp4
            
.
├── Some crappy episode.mp4
├── Load of bollocks.mp4
            

Simple filename cleanup

$ rnm --regex --find '.*_(\d+)_.*' --replace 'Video $1.mp4' *
BeforeAfter
.
├── [ag]_Annoying_filename_-_3_[38881CD1].mp4
├── [ag]_Annoying_filename_-_34_[38881CD1].mp4
├── [ag]_Annoying_filename_-_53_[38881CD1].mp4
            
.
├── Video 3.mp4
├── Video 34.mp4
├── Video 53.mp4
            

if not already done, add your name to a load of files

$ rnm --regex --find '(data\d)(\.\w+)' --replace '$1 (checked by Lloyd)$2' *
BeforeAfter
.
├── data1.csv
├── data2 (checked by Lloyd).csv
├── data3.xls
            
.
├── data1 (checked by Lloyd).csv
├── data2 (checked by Lloyd).csv
├── data3 (checked by Lloyd).xls
            

rename files and folders, recursively

$ rnm --find 'pic' --replace 'photo' '**/*'
BeforeAfter
.
├── pic1.jpg
├── pic2.jpg
└── pics
    ├── pic3.jpg
    └── pic4.jpg
            
.
├── photo1.jpg
├── photo2.jpg
└── photos
    ├── photo3.jpg
    └── photo4.jpg
            

prefix files and folders, recursively

$ rnm --regex --find '^' --replace 'good-' '**/*'
BeforeAfter
.
├── pic1.jpg
├── pic2.jpg
└── pics
    ├── pic3.jpg
    └── pic4.jpg
            
.
├── good-pic1.jpg
├── good-pic2.jpg
└── good-pics
    ├── good-pic3.jpg
    └── good-pic4.jpg