Trimming Media Filenames Using ZSH

Converting media filenames using zmv. Use zmv -n to check the conversion prior to actually doing it.


Filenames of the form:

1.1\ -\ City\ Of.mkv 

Convert to:

S1E1.City\ Of.mkv

using

zmv '(*)1.(*)' 'S1E${2// - /.}'

To shift multiple files from many folders into a new folder, ie this:

Foo\
 |---Season 1
 |     |--Extra.S1.name.avi
 |---Season 2 
       |--Extra.S2.name.avi

to this:

Foo
 |---Season 0
 |     |--Extra.S1.name.avi
 |     |--Extra.S2.name.avi
 |---Season 1
 |---Season 2

We can use the zsh globbing feature **, like this:

cd Foo && mkdir Season\ 0
mv **/*Extra* Season\ 0/

Renaming every file in a series of subdirectories matching a certain pattern.

Original File structure and naming scheme:

Foo
 |---Season 1
       |-- 1.1 - Foo.avi
       |-- 1.2 - Bar.avi
       |-- 1.11 - Baz.avi
 |---Season 2
       |-- 2.1 - Foobar.avi
       |-- 2.12 - Bazbar.avi

Desired file structure and naming scheme:

Foo
 |---Season 1
       |-- S1E1.Foo.avi
       |-- S1E2.Bar.avi
       |-- S1E11.Baz.avi
 |---Season 2
       |-- S2E1.Foobar.avi
       |-- S2E12.Bazbar.avi

Commands:

cd Foo    
# To match "x.x" numbering:
zmv -n '(**/)([0-9]).([0-9]*) - (*)' '${1}S${2}E${3}.${4}'
# To match "x.xx" numbering:
zmv -n '(**/)([0-9]).([0-9][0-9]*) - (*)' '${1}S${2}E${3}.${4}'

To fix double-dots in filenames (if filename has no name)

zmv '(**/)(*)' '${1}${2//../.}'