Powershell script help

Hi all,

I’m in the process of getting my head around PowerShell. To learn, and to produce something I could make use of, I’m writing a script to take all of my mp3s and pop them into folders by the artist name… (they are named ‘artist - track’). This is relatively easy, split on ‘-’ and take the first string from the array. It will always be there as they all have ‘-’ in the name and with a little trimming, I have the folder name.

However, where im struggling is adding the ability to ignore anything in the artist name after ‘ft.’ or ‘vs’ etc. E.g. ‘Craig David ft. Eminem’ I would just want the folder as ‘Craig David’.

I’m not sure how to split on multiple strings without doing them one at time, and if i did that I’m not sure how to ensure there is a result. Any advice would be gratefully received.

Welcome to the forum. :wave:t4:

Since the -split operator works with regex it’s pretty easy to specify more than one split character:

('Craig David ft. Eminem' -split 'ft|-|vs')[0].trim()

Regex, great… I wasn’t aware you could do it like that… thanks.

Do you know what I will get it there isn’t an ‘ft.’ or ‘vs’. will 0 array just be the original value?

The easiest way to figure that out is to try it. :wink: :+1:t4:

('Craig David ft. Eminem' -split 'ft|-|vs')[0].trim()
('Craig David and Eminem' -split 'ft|-|vs')[0].trim()
('Craig David with Eminem' -split 'ft|-|vs')[0].trim()
('Craig David - Rewind' -split 'ft|-|vs')[0].trim()
('Craig David vs I have no idea' -split 'ft|-|vs')[0].trim()

Will do, thanks… appreciate the help