Page 1 of 1

Batch Rename with meta data

Posted: 26 Apr 2016 21:41
by kunkel321
I know there must be some threads with examples of this already...
I have a slew of (mostly nonfiction) books in digital format. Many of them have file names that are not descriptive of what the book is, so I'd like to do a batch rename. I've found that I can add columns to show "Author" and "Title." So, presumably, that info can be used for a rename. Unfortunately "Year" doesn't provide the publication year. I checked the meta data for several books and I don't think the publication year is even in there. At least not in PDF files. I also have some MOBI and EPUB, but none of the info shows for them at all (at least not in the columns). Some (but not all) of the current file names actually do have a year in the file name. So my idea is something like this made up code:

Code: Select all

NOT REAL CODE.
<Title> & "--" & (regex for two first whole words in <Author>) & "(" & (regex to extract year from base file name) & ")" .extension 
I can probably do the regexs, I just need to know how to use them in a batch rename. Also, how do you insert the meta data items?

Re: Batch Rename with meta data

Posted: 26 Apr 2016 21:58
by highend
property() is the way to go to retrieve the... properties^^ (if the meta data contains them)

You don't need to display columns to read them from there :) And you'll need a script, a simple
batch rename pattern doesn't cut it...

Re: Batch Rename with meta data

Posted: 26 Apr 2016 22:19
by kunkel321
Thanks Highend!

Re: Batch Rename with meta data

Posted: 26 Apr 2016 22:36
by TheQwerty
You could do it in a sequence of special renames.

1) Use the <prop> variable within a Batch Rename to add the metadata to your file names.

Code: Select all

<prop #21>--<prop #20>--*
(See the help for the Property() scripting command for tips on finding the index and alternatives.)

2) Use a Regular Expression rename to reduce the name further.
This is an exercise left to the reader. ;)


Crafting that regex is going to prove challenging, especially if you want it to gracefully handle cases where the properties were empty. Plus, the properties may contain illegal characters or cause too long file names which could complicate things further.

The only real advantage to this approach vs a script is the ability to undo the renaming of all files in two steps, where the script will perform each rename separately so the action log's 100 item limit might be restrictive. Though with the script you could undo a specific item's renaming instead of having to do all or none.

Re: Batch Rename with meta data

Posted: 27 Apr 2016 15:53
by highend
Regarding your properties (metadata) for the ebooks...

I don't know that much command line tools that can read them :/ At least there is one: ebook-meta.exe from the Calibre package (http://calibre-ebook.com/)

It spits out e.g. Author(s) and the Published date (when it exists), for example:
D:\Users\Highend\Tools\Calibre\Calibre>ebook-meta.exe "D:\Users\Highend\Tools\Calibre\Calibre Library\Terry Brooks\Shannara VIII (77)\Shannara VIII - Terry Brooks.epub"
Title : Shannara VIII
Author(s) : Terry Brooks [Brooks, Terry]
Languages : deu
Published : 2012-03-08T23:00:00+00:00
So what you're trying to achieve is totally possible but requires some (serious) effort. Calibre (portable) itself is a ~180 MB package and you can't just rip it apart to use ebook-meta.exe standalone...

Re: Batch Rename with meta data

Posted: 27 Apr 2016 23:19
by kunkel321
Interesting that you mention Calibre. I've actually had the regular (non-portable) version installed for quite some time but have been experimenting more with it today than ever before. I filled up my OneDrive and needed to point Calibre to another cloud location, so I wiped my Calibre database. My plan was to rename the ebooks (i.e. the files) before re-importing them to Calibre. As it turns out, you can import them, then rename the file on your computer and if you try to re-import the renamed file, Calibre is smart enough to know that it is the same file. This is because it looks at that metadata, not the file name itself. I also noticed (as Highend indicated) that Calibre is able to associate more than just the standard PDF metadata with a file. Apparently it does this by saving the imported PDF in a folder along with a metadata.opf file. Anyway, pretty cool that is is able to fetch that extra info. It's not perfect though.... It was only able to "recognize" a little over half of my books. Another interesting note is that apparently Calibre can bulk save books from its library. And I guess you can set up "save templates" that automatically inserts various metadata. So it might be possible to, not rename, but save as a more appropriately named copy. Of course this doesn't address the regex concerns addressed above.

Other related notes: Over the years, I've always used ReNamer for my bulk rename jobs. This is actually the first time I've been unable to use it for a job. About 9 years ago (based on my forum search) there was a working set up with ReNamer and an "xpdf" tool accessed via script. Iv'e tried to import the tool into the current ReNamer, but have had problems. ReNamer is nice because it is "stepped out" so I could insert metadata with step 1, and then clean it up with regexes in step 2. Having all the steps prearranged allows you to avoid duplicate names and such. Also noteworthy is that Total Commander actually does bridge the gap between metadata and GUI. You have to import a third party plug in (it doesn't recognize pdf metadata "out of the box" like xyplorer does), but after that you can insert the fields into the multi-rename tool. The tool is kludgy though, and, like xy, you can only make one change at a time (one pass to add files, another for regex changes, and so on.)

Anyhow... I will definitely check out this ebook-meta.exe that is associated with Calibre!