Page 2 of 2
Re: Batch rename PDF files using metadata?
Posted: 26 Mar 2012 20:13
by highend
@perseid
Code: Select all
global $File, $FileName;
$SelectedItems = get("SelectedItemsPathNames", "|");
foreach($Item, $SelectedItems, "|") {
$File = $Item;
sub "_SplitFileName";
$Title = property("DocTitle", "$Item");
$Author = property("DocAuthor", "$Item");
if($Title != "" && $Author != "") {
$NewName = "$Author" . "_" . "$Title" . "_" . "$FileName";
rename b, "$NewName", p, "$Item";
}
}
"_SplitFileName"
global $File, $FileName;
// Separate file components
$FindBS = strpos($File, "\", -1);
$FindExt = strpos($File, ".", -1);
$FileName = substr($File, $FindBS +1, ($FindExt - $FindBS -1));
@serendipity
It's not that I don't trust you. I don't trust the property command (or better: the OS that returns back a value). The same script will fail miserably on my OS while it works for perseid and I like to prefer a solution that works on all systems.
Re: Batch rename PDF files using metadata?
Posted: 26 Mar 2012 20:22
by serendipity
highend wrote:
It's not that I don't trust you. I don't trust the property command (or better: the OS that returns back a value). The same script will fail miserably on my OS while it works for perseid and I like to prefer a solution that works on all systems.
Hey! I was just joking,

i understand fully how it is with properties. Don himself mentioned about the OS dependency thing when he gave us property command.
And that's precisely why I made the property script, so that users can read items and figure out property names.
Re: Batch rename PDF files using metadata?
Posted: 26 Mar 2012 20:38
by perseid
highend wrote:@perseid
Code: Select all
global $File, $FileName;
$SelectedItems = get("SelectedItemsPathNames", "|");
foreach($Item, $SelectedItems, "|") {
$File = $Item;
sub "_SplitFileName";
$Title = property("DocTitle", "$Item");
$Author = property("DocAuthor", "$Item");
if($Title != "" && $Author != "") {
$NewName = "$Author" . "_" . "$Title" . "_" . "$FileName";
rename b, "$NewName", p, "$Item";
}
}
"_SplitFileName"
global $File, $FileName;
// Separate file components
$FindBS = strpos($File, "\", -1);
$FindExt = strpos($File, ".", -1);
$FileName = substr($File, $FindBS +1, ($FindExt - $FindBS -1));
Thanks highend! The script works flawlessly, but as I wrote in my previous post I wanted the renaming to append as follows: "<Title>_<Author>_originalfilename.pdf" instead of "<Author>_<Title>_originalfilename.pdf". Also, is it possible that when I run the script the preview rename confirm window is not shown for each PDF and instead the batch renaming is done for the selected files with a single click? Thanks.
Re: Batch rename PDF files using metadata?
Posted: 26 Mar 2012 20:50
by highend
I wanted the renaming to append as follows: "<Title>_<Author>_originalfilename.pdf"
Just change this line to whatever you prefer:
Code: Select all
$NewName = "$Author" . "_" . "$Title" . "_" . "$FileName";
e.g.:
Code: Select all
$NewName = "$Title" . "_" . "$Author" . "_" . "$FileName";
Also, is it possible that when I run the script the preview rename confirm window is not shown for each PDF and instead the batch renaming is done for the selected files with a single click?
(just delete the "p" character on that line)
Re: Batch rename PDF files using metadata?
Posted: 26 Mar 2012 21:25
by perseid
highend wrote:I wanted the renaming to append as follows: "<Title>_<Author>_originalfilename.pdf"
Just change this line to whatever you prefer:
Code: Select all
$NewName = "$Author" . "_" . "$Title" . "_" . "$FileName";
e.g.:
Code: Select all
$NewName = "$Title" . "_" . "$Author" . "_" . "$FileName";
Also, is it possible that when I run the script the preview rename confirm window is not shown for each PDF and instead the batch renaming is done for the selected files with a single click?
(just delete the "p" character on that line)
Thanks highend, works flawlessly. Will the script work for any file extension or just for PDF's?
Also, I want to learn how to write these scripts myself. I have zero knowledge and experience. Can you recommend a book or link to start learning the basics? Thanks.
This script run in XYplorer will perfectly meet my needs. Thanks again!
I want to mention 3rd party utilities that I tried or searched before attempting XYplorer:
http://www.boxoft.com/pdf-renamer/
I tested the trial version, very unstable, it crashed before being able to use it
http://download.cnet.com/A-PDF-Rename/3 ... 23008.html
I have not tested it
http://www.mendeley.com/
They have a free desktop application, it will not always read the metadata. Handy though to rename PDF files without metadata.
Re: Batch rename PDF files using metadata?
Posted: 26 Mar 2012 21:33
by j_c_hallgren
perseid wrote:Also, I want to learn how to write these scripts myself. I have zero knowledge and experience. Can you recommend a book or link to start learning the basics? Thanks.
Presume you've seen and read
http://www.xyplorer.com/tour/index.php?page=scripting and
http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=5750 and
http://www.xyplorer.com/xyfc/viewtopic. ... 436#p60436 already? Those are some starting threads/pages to read...
There's no book on it but it does follow a lot of conventions of similar langauges..
Re: Batch rename PDF files using metadata?
Posted: 26 Mar 2012 21:34
by highend
Will the script work for any file extension or just for PDF's?
For any. But ofc you have to change the script if you want to use other properties than DocAuthor and DocTitle.
Can you recommend a book or link to start learning the basics?
Open the help file (F1) and read through Advanced Topics - Scripting / Scripting Commands Reference and visit the script exchange part of the board:
http://www.xyplorer.com/xyfc/viewforum.php?f=7 to learn from what is posted there.
There aren't any books about XYplorer's scripting language (at least afaik) so it's practicing and reading the help file
