Reputation: 171
I am trying to batch add text to the titles of several files in a folder. My code works for command line but not PowerShell:
for %a in (*.avi, *.mta) do ren "%a" "My Title - %a"
Could someone help me adapt this to powershell?
Basically I would like to perform the following actions:
Folder Contents:
001-episode.avi 002-episode.avi
I would like to add the name of the show to the file
ShowTitle-001-episode.avi ShowTitle-002-episode.ave
Thank you.
Upvotes: 6
Views: 24979
Reputation: 67
Somehow the answers here didn't work for me, they just changed the name to the string part without the $_.Name. For example, if I renamed test.txt with Dir | rename-item -newname { "My Title -" + $_.Name }
it would just rename it to
My Title -
But this worked
gci F:path *wildcard -depth 2 | % { rename-item –path $_.Fullname –Newname ( 'My Title -' + $_.basename + $_.extension)}
Upvotes: 0
Reputation: 31
get-childitem * | rename-item -newname { "My Title -" + $_.Name }
Upvotes: 3
Reputation: 171
Found this to work as well.
Dir | rename-item -newname { "My Title -" + $_.Name }
Upvotes: 11
Reputation: 11401
Get-ChildItem *.avi,*.mta | ForEach-Object {
Rename-Item -Path $_.Name -NewName "My Title - $($_.Name)"
}
Upvotes: 3