Page 1 of 1

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

Posted: 04 Jul 2021 06:29
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.

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

Posted: 04 Jul 2021 06:52
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;
   }

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

Posted: 05 Jul 2021 22:08
by kiwichick
Thank you so much highend, that works perfectly!