Renaming selected files with a property

Discuss and share scripts and script files...
Post Reply
tuomo
Posts: 4
Joined: 29 Nov 2015 16:24

Renaming selected files with a property

Post 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";};

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Renaming selected files with a property

Post 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;};
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

tuomo
Posts: 4
Joined: 29 Nov 2015 16:24

Re: Renaming selected files with a property

Post by tuomo »

Thank you very much for quick answer. Your script works perfectly.

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Renaming selected files with a property

Post 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).

tuomo
Posts: 4
Joined: 29 Nov 2015 16:24

Re: Renaming selected files with a property

Post by tuomo »

Oh. I thought " equals '
Good to know.

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

Post Reply