Batch Rename any type of file

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

Batch Rename any type of file

Post by rednoah » 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 hit F2
4. New Names will instantly filled with File objects (or Episode / Movie objects if xattr metadata has previously been stored)
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.


Batch 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)} - iPhone {fn.after('IMG_') as int}
i ... item number, fn ... current filename
Image


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. Something like The Bold and The Beautiful - 2014.08.04 will immediately be 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.
Image


Batch Rename files based on text content

Generating new filenames based on the text content of the files can be very useful when normalizing a set of text files.

Code: Select all

Report {i.pad(2)} {file.text.match(/\(.+\)/)}
Match first (...) pattern from the text content and add it to the filename.
Image


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

Assuming a file structure like so:

Code: Select all

name.cbz
name.xml
The contents of the .xml file looking something like this:

Code: Select all

<ComicInfo>
	<Title>Ask Not</Title>
	<Series>The American Way</Series>
	<Number>1</Number>
</ComicInfo>
And a Groovy format:

Code: Select all

{xml = new XmlSlurper().parse(folder/fn+'.xml'); [xml.Series, xml.Number, xml.Series, xml.Title].join(' - ')}
You'll get output paths like this:

Code: Select all

The American Way - 1 - The American Way - Ask Not
My (very excellent) support depends on Windows Store and Mac App Store sales and PayPal donations. Paying users, donors and everyone who contributes to FileBot in one way or another will get the very best support.

Image

Please read the FAQ and How to Request Help. Donate if you'd like some extra developer love. :ugeek:

dadelayer
Posts: 5
Joined: 06 Oct 2017, 06:18

Re: Batch Rename any type of file

Post by dadelayer » 06 Oct 2017, 21:22

Thanks!. I tested it out using the example and it worked fine. However, when I use it with my XML file (I converted the JSON > XML), it says my format is not correct.
I use the same format and code as the example

User avatar
rednoah
The Source
Posts: 12609
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Batch Rename any type of file

Post by rednoah » 07 Oct 2017, 07:42

The example here is very specific. You can learn from it, but you can't copy-and-paste and expect it to work in your case. ;)

If you start by learning how to parse JSON, then you're on the right track:
http://docs.groovy-lang.org/latest/html ... urper.html

:idea: You can hire me though, but you'd need to write down exactly what you need, with examples and example data.
My (very excellent) support depends on Windows Store and Mac App Store sales and PayPal donations. Paying users, donors and everyone who contributes to FileBot in one way or another will get the very best support.

Image

Please read the FAQ and How to Request Help. Donate if you'd like some extra developer love. :ugeek:

dadelayer
Posts: 5
Joined: 06 Oct 2017, 06:18

Re: Batch Rename any type of file

Post by dadelayer » 07 Oct 2017, 08:09

Well, I wanted to try it in XML since I wanted to use your example, but not coming up with anything.

Code: Select all

def fnn = fn
xml = new XmlSlurper().parse(folder+'/mov.xml')
xml.'**'.find { it.name() == 'scid' && it.text() == fnn}*.parent()*.title*.text()
that should return the title but it's not working as its supposed to. I don't have the money to hire :\ it seems expensive :(

User avatar
rednoah
The Source
Posts: 12609
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Batch Rename any type of file

Post by rednoah » 07 Oct 2017, 10:14

Just debug step by step. Does it parse? Is the first element what you think it should be?

You can prototype and debug these things in the Format Editor in minutes. Just try things and narrow down which exact piece of code isn't working as expected. ;)
My (very excellent) support depends on Windows Store and Mac App Store sales and PayPal donations. Paying users, donors and everyone who contributes to FileBot in one way or another will get the very best support.

Image

Please read the FAQ and How to Request Help. Donate if you'd like some extra developer love. :ugeek:

Delmano
Posts: 1
Joined: 14 Oct 2017, 10:27

Re: Batch Rename any type of file

Post by Delmano » 24 Oct 2017, 12:51

This is so useful. Thanks for the tutorial Noah, helps newbies like me a lot.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests