[Plain File Mode] Batch Rename any type of file
Posted: 13 Oct 2014, 21:47
As a hidden bonus feature, FileBot supports quick and efficient generic batch renaming, and you can rewrite the filenames with awesome Groovy expressions just like in Episode / Movie mode.
1. Drop files into Original Files
2. Click on the empty New Names component
3. Now that New Names has focus press F2 (for Plain File Mode) or F3 (for Local Xattr Mode)
4. New Names will instantly filled with File objects (in Plain File Mode) or Movie / Episode objects (in Local Xattr Mode)
5. Double Click any item in New Names to apply a new Format Expression
Create Presets for repetitive tasks.
Hit F2 after selecting an item to edit the name.
Hit F3 after selecting an item to select a different metadata object.
--db file and --db xattr can be used for Plain File Mode and Local Xattr Mode on the command-line.
Rename photos
Add a fixed prefix (e.g. place taken) and a serial number at the beginning of the file name for sorting purposes, followed by which camera model took the photo, and preserve the photo number from the original filename at the end of the new file name.
i ... item number, fn ... current filename

Pre-Process badly named episode files
FileBot cannot process badly named files like B&B Aug 4 - 14 so you will need to fix it first. The Bold and The Beautiful - 2014.08.04 is much more sensible.
Extract, parse and re-format the date.

Move files into a new folders based on the file name
You can convert a flat file structure into a nested file structure (e.g. one file per folder) by generating a new file path for each file based on the current file name.

e.g.
Rename media files based on embedded media title tags
If you have suffered from data loss, and your data recovery software was only able to restore file contents, but not file names or folder structures, then you may be able to use metadata embedded in the file content to restore the original filenames.

e.g.
Organize files based on information present in the file path
You can use Groovy code and regular expressions to extract pieces of information from the file path, and then use those pieces to generate a new file path.

Rename media files based on Plex database
Tautulli allows us to export everything that Plex knows as machine-readable XML file, so we can write a format that generates file names based on that.
Rename files based on sibling XML files
In your format you have access to other files or web resources so you can easily build powerful rename logic for your own unique use cases.
Let's assume a file structure where each media file is accompanied by an XML metadata file:
e.g. name.xml
Generate the desired file path based on the information in the sibling XML file:
Additional Examples and Use Cases
1. Drop files into Original Files
2. Click on the empty New Names component
3. Now that New Names has focus press F2 (for Plain File Mode) or F3 (for Local Xattr Mode)
4. New Names will instantly filled with File objects (in Plain File Mode) or Movie / Episode objects (in Local Xattr Mode)
5. Double Click any item in New Names to apply a new Format Expression




Rename photos
Add a fixed prefix (e.g. place taken) and a serial number at the beginning of the file name for sorting purposes, followed by which camera model took the photo, and preserve the photo number from the original filename at the end of the new file name.
Code: Select all
Taiwan { i.pad(3) } - { camera.model } { fn.after('IMG_') as int }

Pre-Process badly named episode files
FileBot cannot process badly named files like B&B Aug 4 - 14 so you will need to fix it first. The Bold and The Beautiful - 2014.08.04 is much more sensible.
Code: Select all
{Date.parse('MMM dd - yy', fn.after(/\s/)).format('yyyy.MM.dd')}

Move files into a new folders based on the file name
You can convert a flat file structure into a nested file structure (e.g. one file per folder) by generating a new file path for each file based on the current file name.
Code: Select all
~/Movies/{fn}/{fn}

e.g.
Code: Select all
$ filebot -rename /path/to/files --db file --format "{fn}/{fn}"
Rename files using [Plain File]
[MOVE] from [Avatar (2009).mkv] to [Avatar (2009)/Avatar (2009).mkv]
Rename media files based on embedded media title tags
If you have suffered from data loss, and your data recovery software was only able to restore file contents, but not file names or folder structures, then you may be able to use metadata embedded in the file content to restore the original filenames.
Code: Select all
{mediaTitle}

e.g.
Code: Select all
$ filebot -rename -r /path/to/files --db file --filter mediaTitle --format {mediaTitle}
Rename files using [Plain File]
[MOVE] from [Babylon.5.S04E22.mkv] to [bab4d6-VTS_01_0-PGC3.mkv]
Organize files based on information present in the file path
You can use Groovy code and regular expressions to extract pieces of information from the file path, and then use those pieces to generate a new file path.
Code: Select all
{
def n = folder.dir.name
def s = folder.name.before(/[.]/)
def c = folder.name.after(/[.]/)
def e = fn.before(/[.]/)
def t = fn.after(/[.]/)
"$n/Season $s - $c/$n - S${s.pad 2}E${e.pad 2} - $t"
}

Rename media files based on Plex database
Tautulli allows us to export everything that Plex knows as machine-readable XML file, so we can write a format that generates file names based on that.
Code: Select all
{
// find <part> element for the file at hand
def dom = xml('/path/to/library.xml')
def part = dom.show.season.episode.media.part.find{ it.'@file'.text().toFile().name == f.name }
// navigate parent elements and access attributes
def n = part.'..'.'..'.'..'.'..'.'@title'.text()
def s = part.'..'.'..'.'..'.'@index'.text() as int
def e = part.'..'.'..'.'@index'.text() as int
def t = part.'..'.'..'.'@title'.text()
// generate file name
"${n} - S${s.pad 2}E${e.pad 2} - ${t}"
}
Code: Select all
Firefly - S01E07 - Jaynestown
Rename files based on sibling XML files
In your format you have access to other files or web resources so you can easily build powerful rename logic for your own unique use cases.

Let's assume a file structure where each media file is accompanied by an XML metadata file:
Code: Select all
name.cbz
name.xml
Code: Select all
<ComicInfo>
<Title>Ask Not</Title>
<Series>The American Way</Series>
<Number>1</Number>
</ComicInfo>
Code: Select all
{
def i = xml(folder / fn + '.xml')
[i.Series, i.Number, i.Title].join(' - ')
}
Code: Select all
The American Way - 1 - Ask Not
Additional Examples and Use Cases