Page 1 of 1

Script that would rename a file based on subfolder?

Posted: 29 Aug 2015 01:05
by Vocalpoint
Looking for some XY help in reorganizing hundreds of scanned "CD" asset archive files (Cover,booklet, disc etc) that all have the same name (artwork.rar) and all exist in a folder structure that looks like this:

Album Assets->P-Pink Floyd->The Wall->Artwork.rar

Ideally in XYPlorer - I would like to be able to select any "artwork.rar" file and run a script that instantly renames it based on the name of its current folder (The Wall) and the folder above it (Pink Floyd). Effectively resulting in a file named Pink Floyd - The Wall.rar. Spaces and dash included.

Anyone have anything like this? Or could point me to how to tackle it?

Cheers!

VP

Re: Script that would rename a file based on subfolder?

Posted: 29 Aug 2015 01:21
by highend
Haaaaaard!

Code: Select all

if (exists("<curitem>") == 1) { renameitem(getpathcomponent("<curitem>", "parent") . " - " . getpathcomponent("<curitem>", "component", -3)); }

Re: Script that would rename a file based on subfolder?

Posted: 29 Aug 2015 01:31
by Vocalpoint
highend wrote:Haaaaaard!

Code: Select all

if (exists("<curitem>") == 1) { renameitem(getpathcomponent("<curitem>", "parent") . " - " . getpathcomponent("<curitem>", "component", -3)); }
Wow! Sweet

However - the rename ends up being in reverse. I am getting The Wall - Pink Floyd.rar

What do I need to swap around?

VP

Re: Script that would rename a file based on subfolder?

Posted: 29 Aug 2015 01:34
by highend
Guess...

Both getpathcomponents statements?

Code: Select all

if (exists("<curitem>") == 1) { renameitem(getpathcomponent("<curitem>", "component", -3) . " - " . getpathcomponent("<curitem>", "parent")); }

Re: Script that would rename a file based on subfolder?

Posted: 31 Aug 2015 15:45
by Vocalpoint
highend wrote:Guess...

Both getpathcomponents statements?

Code: Select all

if (exists("<curitem>") == 1) { renameitem(getpathcomponent("<curitem>", "component", -3) . " - " . getpathcomponent("<curitem>", "parent")); }
I got this one working - but now - I have issues with the Parent folder name has a "dot" in the title. So when I attempt to rename a structure like this:

B.B. King\Blues Is King\Artwork.rar

Instead of getting:

B.B. King - Blues Is King.rar

I get the right filename but a very weird extension...

B.B. King - Blues Is King.king - blues is king

Any ideas how to prevent a "." in a folder name from being detected as a separator for the extension?

Really appreciate all your help.

Cheers!

VP

Re: Script that would rename a file based on subfolder?

Posted: 31 Aug 2015 16:30
by highend

Code: Select all

if (exists("<curitem>") == 1) { renameitem(getpathcomponent("<curitem>", "component", -3) . " - " . getpathcomponent("<curitem>", "parent"), , 1); }

Re: Script that would rename a file based on subfolder?

Posted: 31 Aug 2015 16:32
by admin
Would anybody object if I add an alias "gpc" to "getpathcomponent"...? ;)

Re: Script that would rename a file based on subfolder?

Posted: 31 Aug 2015 16:42
by highend
As long as it's documented, no objection :)

Re: Script that would rename a file based on subfolder?

Posted: 01 Sep 2015 18:30
by Vocalpoint
highend wrote:

Code: Select all

if (exists("<curitem>") == 1) { renameitem(getpathcomponent("<curitem>", "component", -3) . " - " . getpathcomponent("<curitem>", "parent"), , 1); }

Awesome! Thanks again!

VP