Objective: remove (notes) from filenames e.g., Cassidy (Series) - Notebook.html
Best effort:
$TargetPath = 'C:\Users\flana\TC_temp'
Get-ChildItem $TargetPath *.html |
Foreach {
rename-item $_.Fullname $_.Fullname.Replace('\(.*\) ', '')
}
Result: runs with no errors but files are not renamed. What in the world am I doing wrong?
anagy
2
So you have a filename such as 'Cassidy (Series) - Notebook.html
and you’re trying to make it like 'Cassidy (Series) - book.html?
The Replace()
method of object type String
doesn’t support regex replacement. You could do this:
Rename-Item $_.FullName ($_.FullName -replace '\(.*\) ')
1 Like
No, @anagy, I want to remove the parens and all text within them, e.g., "Cassidy - Notebook.html
@matt-bloomfield I surely must have read that but could not get it right. Thanks a BUNCH, it is what I needed. (Here comes a stealth hug!)