I have a bunch of files that have names that start with numbers, may contain spaces and dashes after one of two numbers, then sometimes (sometimes not) have a space just before the first alpha character of the name I want to keep, i.e.:
2-01 Dazed And Confused.txt (I want to rename this to Dazed And Confused.txt)
Or
02 - Uncle Salty.txt (I want to rename this to Uncle Salty.txt)
Or
02-The Night Before.txt (I want to rename to The Night Before.txt)
The Move-Item
and Rename-Item
cmdlets can accept the source directly from the pipeline and provide a new name using a script block:
dir | Move-Item -Destination { $_.Name -replace '^([0-9\-\s]*)' }
or
dir | Rename-Item -NewName { $_.Name -replace '^([0-9\-\s]*)' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With