[Plain File Mode] Batch Rename any type of file

How-to guides, frequently asked questions, not-so-obvious features, etc
User avatar
The Source
Posts: 21959
Joined: 16 Nov 2011, 08:59

[Plain File Mode] Batch Rename any type of file

Post by rednoah »

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

:idea: Create Presets for repetitive tasks. You can use Presets to create custom buttons for your custom use cases.


:idea: Hit F2 or CTRL+N after selecting an item to edit the name.

:idea: Hit F3 or CTRL+M after selecting an item to select a different metadata object.

:idea: --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.

Code: Select all

Taiwan { i.pad(3) } - { camera.model } { fn.after('IMG_') as int }
i ... item number, fn ... current filename

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. :ugeek:

Let's assume a file structure where each media file is accompanied by an XML metadata file:

Code: Select all

e.g. name.xml

Code: Select all

	<Title>Ask Not</Title>
	<Series>The American Way</Series>
Generate the desired file path based on the information in the sibling XML file:

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
:idea: Please read the FAQ and How to Request Help.