shenwei356 / brename

A practical cross-platform command-line tool for safely batch renaming files/directories via regular expression
https://github.com/shenwei356/brename
MIT License
262 stars 22 forks source link

incrementing numbered files/folders #9

Closed sathishvj closed 6 years ago

sathishvj commented 6 years ago

Sometimes, I have a list of files/folders that I've numbered to keep track of order. So I start off with:

001_a 002_b 003_c 004_d

Then I realize that I want to add a new folder between a and b. So now it has to be 001_a, 002_adash, 003_b, 004_c, 005_d.

Is there a pattern I can use to increment the numbers in from folder 002_b onwards?

Similarly, there might be a requirement to decrement the numbers if I delete a folder in between.

shenwei356 commented 6 years ago

using

-n/--start-num

moving files in front of where you want insert to somewhere, renaming and moving them back.

same operation for deletion.

shenwei356 commented 6 years ago

Have you try it? Here are the steps:

  1. Insertion.
# 1. move 001_a to somewhere (out of current directory)

# 2. rename left dirs
$ brename -D -p '^\d+_(.+)' -r '{nr}_$1'  --nr-width 3 -n 3 
[INFO] checking: [ ok ] '002_b' -> '003_b'
[INFO] checking: [ ok ] '003_c' -> '004_c'
[INFO] checking: [ ok ] '004_d' -> '005_d'
[INFO] 3 path(s) to be renamed

# 3. mv 002_adash and 001_a to current dir 
  1. Deletion (taking 002_b for example).
# 1. move 001_a to somewhere (out of current directory)

# 2. remove 002_b

# 3. rename left dirs
$ brename -D -p '^\d+_(.+)' -r '{nr}_$1'  --nr-width 3 -n 2
[INFO] checking: [ ok ] '003_c' -> '002_c'
[INFO] checking: [ ok ] '004_d' -> '003_d'
[INFO] 2 path(s) to be renamed

# 4. mv 001_a back to current dir