Move 'artist - album' folders to 'artist' folders

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Move 'artist - album' folders to 'artist' folders

Post by kiwichick »

Hi everyone, I hope this makes sense and I apologise of it's been asked before but I can't find anything with search.

My music is sorted in folders named 'artist - album' (eg: ACDC - Back In Black). I would like to be able to select a bunch of folders and run a script that will move them to folders named after the artist portion of the folder name (eg: ACDC - Back In Black would move to a folder named ACDC).

I have this script that moves selected files to folders named after each of the files:

Code: Select all

   end(getinfo("CountSelected") < 1), "Nothing selected!";
   foreach($file, get("SelectedItemsPathNames", "|"), "|") {
   $baseName = getpathcomponent($file, "base");
   moveto "<curpath>\$baseName", "$file", , 2;
	}
I was thinking I could modify it to something like this:

Code: Select all

   end(getinfo("CountSelected") < 1), "Nothing selected!";
   foreach($folder, get("SelectedItemsPathNames", "|"), "|") {
   $baseName = getpathcomponent($folder, "base");   
   $artistName = $baseName before hyphen   
   moveto "<curpath>\$artistName", "$folder", , 2;
	}
Will this work? And if so, what is the code I need for the "$baseName before hyphen" part? I guess it's probably going to be some kind of regex but I can't figure out what it should be.

Thanks in advance for any help.
Windows 10 Pro 22H2

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

Re: Move 'artist - album' folders to 'artist' folders

Post by highend »

Code: Select all

   end(getinfo("CountSelected") < 1), "Nothing selected!";
   foreach($folder, get("SelectedItemsPathNames", "|"), "|") {
       $baseName   = getpathcomponent($folder, "file");
       $artistName = gettoken($baseName, 1, " - ", "t");
       moveto "<curpath>\$artistName", $folder, , 2;
   }
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Move 'artist - album' folders to 'artist' folders

Post by kiwichick »

Thank you so much highend, that works perfectly!
Windows 10 Pro 22H2

Post Reply