[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: 19706
Joined: 16 Nov 2011, 08:59
Location: Taipei

[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.

:idea: Hit F2 after selecting an item to edit the name.

:idea: Hit F3 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

When organizing photos, I use the place where I took them and a serial number as the beginning of the filename (for sorting), followed by which camera took it and the photo number from the original filename.

Code: Select all

Taiwan {i.pad(3)} - Timer {fn.after('IMG_') as int}
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.

Code: Select all

{Date.parse('MMM dd - yy', fn.after(/\s/)).format('yyyy.MM.dd')}
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.

Code: Select all


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


Code: Select all

$ filebot -rename /path/to/files --db file --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 XMLmetadata 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.