[Plain File Mode] Batch Rename any type of file

How-to guides, frequently asked questions, not-so-obvious features, etc
Locked
User avatar
rednoah
The Source
Posts: 23218
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

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

Screenshot

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

Format: Select all

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

Console Output: 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.

Format: Select all

~/Movies/{ fn }/{ fn }
Screenshot

Console Output: 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.

Format: Select all

{ mediaTitle }
Screenshot

Console Output: 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.

Format: 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"
}
Screenshot



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.

Format: 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}"
}

Console Output: Select all

$ ls
Firefly - S01E07 - Jaynestown.mkv




Rename files based on sibling properties files

If each of your media files is accompanied by a properties metadata file, then you can use that information to generate new file paths:

Console Output: Select all

$ ls
name.ts
name.properties

Properties: Select all

MediaProviderID=tvdb
MediaProviderDataID=78107
Title=The Office
SeasonNumber=6
EpisodeNumber=17
EpisodeName=The Delivery

Format: Select all

{
	def m = lines(folder / fn + '.properties').collectEntries{ it.split('=') }
	"$m.Title {$m.MediaProviderID-$m.MediaProviderDataID}/$m.Title - S${m.SeasonNumber.pad(2)}E${m.EpisodeNumber.pad(2)} - $m.EpisodeName"
}

Console Output: Select all

$ ls
The Office {tvdb-78107}/The Office - S06E17 - The Delivery.ts
The Office {tvdb-78107}/The Office - S06E17 - The Delivery.properties




Rename files based on sibling XML files

If each of your media files is accompanied by a XML metadata file, then you can use that information to generate new file paths:

Console Output: Select all

$ ls
name.cbz
name.xml

xml: Select all

<ComicInfo>
	<Title>Ask Not</Title>
	<Series>The American Way</Series>
	<Number>1</Number>
</ComicInfo>

Format: Select all

{
	def i = xml(folder / fn + '.xml')
	[i.Series, i.Number, i.Title].join(' - ')
}

Console Output: Select all

$ ls
The American Way - 1 - Ask Not.cbz
The American Way - 1 - Ask Not.xml




Additional Examples and Use Cases

:idea: Please read the FAQ and How to Request Help.
Locked