I have a folder containing video lectures on some particular topic. It is structured like this:
.
├── 1_fol
│ ├── 1_file.mp4
│ ├── 2_file.mp4
│ └── 3_file.mp4
└── 2_fol
├── 10_file.mp4
├── 4_file.mp4
├── 5_file.mp4
├── 6_file.mp4
├── 7_file.mp4
├── 8_file.mp4
└── 9_file.mp4
I want to change this structure into
.
├── 001_fol
│ ├── 001_file.mp4
│ ├── 002_file.mp4
│ └── 003_file.mp4
└── 002_fol
├── 004_file.mp4
├── 005_file.mp4
├── 006_file.mp4
├── 007_file.mp4
├── 008_file.mp4
├── 009_file.mp4
└── 010_file.mp4
This helps, because you can then use find . -regextype sed -regex ".*/.*\.\(mp3\|mp4\)" -print0 | sort -z | xargs -r0 vlc
to open the whole playlist. I came up with a script to pad 0's, but it's quite lengthy and slow:
find . -depth -exec rename -v 's/(.*)\/([0-9]$)/$1\/00$2/;
s/(.*)\/([0-9]{2}$)/$1\/0$2/;
s/(.*)\/([0-9][^0-9][^\/]*$)/$1\/00$2/;
s/(.*)\/([0-9]{2}[^0-9][^\/]*$)/$1\/0$2/' '{}' ';'
Can this be optimized further?
Edit
Actually, the execution became quite fast after the ';' was changed to '+'. But the set of regex(es) still looks quite ugly.