Script that would rename a file based on subfolder?

Discuss and share scripts and script files...
Post Reply
Vocalpoint
Posts: 163
Joined: 06 Nov 2009 14:01

Script that would rename a file based on subfolder?

Post 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

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

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

Post by highend »

Haaaaaard!

Code: Select all

if (exists("<curitem>") == 1) { renameitem(getpathcomponent("<curitem>", "parent") . " - " . getpathcomponent("<curitem>", "component", -3)); }
One of my scripts helped you out? Please donate via Paypal

Vocalpoint
Posts: 163
Joined: 06 Nov 2009 14:01

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

Post 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

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

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

Post by highend »

Guess...

Both getpathcomponents statements?

Code: Select all

if (exists("<curitem>") == 1) { renameitem(getpathcomponent("<curitem>", "component", -3) . " - " . getpathcomponent("<curitem>", "parent")); }
One of my scripts helped you out? Please donate via Paypal

Vocalpoint
Posts: 163
Joined: 06 Nov 2009 14:01

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

Post 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

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

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

Post by highend »

Code: Select all

if (exists("<curitem>") == 1) { renameitem(getpathcomponent("<curitem>", "component", -3) . " - " . getpathcomponent("<curitem>", "parent"), , 1); }
One of my scripts helped you out? Please donate via Paypal

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

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

Post by admin »

Would anybody object if I add an alias "gpc" to "getpathcomponent"...? ;)

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

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

Post by highend »

As long as it's documented, no objection :)
One of my scripts helped you out? Please donate via Paypal

Vocalpoint
Posts: 163
Joined: 06 Nov 2009 14:01

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

Post by Vocalpoint »

highend wrote:

Code: Select all

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

Awesome! Thanks again!

VP

Post Reply