I'm working on cleaning up my music library, and I need some help with PowerShell. My goal is to remove the artist names from file names of various artist albums so that my digital audio player doesn't show long track names that get cut off. The files are currently named in the format "artist - track". I want to remove everything before the dash, but the size of the artist name varies, so I'm not sure how to do it efficiently with PowerShell. I have tried using commands like: dir | rename-item -Newname {$_.name -replace "artist - ",""}, which works for specific artist names, but I'm struggling with the non-specific names. I thought about using wildcards but that led to syntax errors. Any guidance would be appreciated!
2 Answers
You might want to try splitting the names using a dash as a separator. Like this:
```powershell
$parts = "artist - title" -split " - "
$parts
```
This way, you can easily manipulate the segments of the file name. A more complete solution would involve looping through your files and renaming them based on the split results!
Honestly, PowerShell might not be the best option for this. You could use a dedicated tagging software like Mp3Tag; it lets you batch rename files based on their current names or ID3 tags. And don’t worry, it’s not just for MP3s—works with other formats too!
Absolutely! I've also heard that MusicBrainz Picard is great for this type of renaming task. Tagging software can really simplify things.

Adding on to that, here's a more thorough example:
```powershell
Get-ChildItem -Path $Path -File -Filter '*.mp3' |
Rename-Item -NewName { '{0}{1}' -f ($_.BaseName -split '-')[1].trim(), $_.Extension } -WhatIf
```
Make sure to adjust the -Path and -Filter settings and check with '-WhatIf' first to see what changes would happen before actually renaming!