[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. You can use Presets to create custom buttons for your custom use cases.

Hit F2 or CTRL+N after selecting an item to edit the name.
Hit F3 or CTRL+M 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
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.
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.
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 }

Code: Select all
$ filebot -rename -r /path/to/files --db exif --format "Taiwan { i.pad(3) } - { camera.model } { fn.after('IMG_') as int }"
Rename files using [Exif Metadata]
[MOVE] from [IMG_0112.jpg] to [Taiwan 001 - Timer 112.jpg]
...
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 }

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 }

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
- Re-organize previously organized files using local xattr metadata
- Offline Cleanup (i.e. strip release information from file name)
- Strip brackets [...] from the file path
- Add missing file extensions
- Rename subtitle files to match the name of a nearby video file
- Match custom patterns and rewrite file paths
- Rename Series Folders