Page 1 of 1

Renaming selected files with a property

Posted: 29 Nov 2015 16:46
by tuomo
Hello,



I am trying to rename multiple pdf files with their DocTitle property.

Here is a script how to rename one selected file:

Code: Select all

::rename b, "<prop doctitle>";
It works great but I would like to rename a bunch of files.

I guess foreach loop is way to go, but with this script it does not work:

Code: Select all

::foreach($item, <get selecteditemspathnames |>, "|") {rename b, "<prop doctitle>",,$item;}
What I get is just this kind of stuff:

DocTitleOfTheFirstSelectedFile.pdf
DocTitleOfTheFirstSelectedFile-1.pdf
DocTitleOfTheFirstSelectedFile-2.pdf
DocTitleOfTheFirstSelectedFile-3.pdf

and so on.


I also tried this but got the same results:

Code: Select all

 ::foreach($item, <get selecteditemspathnames |>, "|") {$property=property("doctitle");rename b, "$property",,"$item";};

Re: Renaming selected files with a property

Posted: 29 Nov 2015 17:05
by bdeshi
tuomo wrote:I also tried this but got the same results:

Code: Select all

::foreach($item, <get selecteditemspathnames |>, "|") {$property=property("doctitle");rename b, "$property",,"$item";};
almost there. What's happening here is that the property()/<prop> function works on the currently selected file by default. What you want to do is provide the current file the loop is operating to property(). So try this:

Code: Select all

::foreach($item, get('SelectedItemsPathNames', '|'), "|") {$property=property("doctitle", $item);rename b, $property,, $item;};

Re: Renaming selected files with a property

Posted: 29 Nov 2015 18:03
by tuomo
Thank you very much for quick answer. Your script works perfectly.

Re: Renaming selected files with a property

Posted: 29 Nov 2015 19:46
by admin
tuomo wrote: I am trying to rename multiple pdf files with their DocTitle property.

Here is a script how to rename one selected file:

Code: Select all

::rename b, "<prop doctitle>";
It works great but I would like to rename a bunch of files.
No need for a loop. Simply put the variable in single quotes (instead of double quotes). That way it is not resolved before it is passed to the rename procedure where it is then resolved file-by-file:

Code: Select all

::rename b, '<prop doctitle>', p;
(Added the "p" argument to get a preview first).

Re: Renaming selected files with a property

Posted: 29 Nov 2015 22:32
by tuomo
Oh. I thought " equals '
Good to know.

Btw thanks for great program Don. Xyplorer is so enjoyable to use.