Reputation: 4187
I have around 400 movies on my hard-disk, but names of those movies contains dots or underscore in between like "wrong_turn.mkv" or "wrong.turn.mkv". I just want to remove these dots or special characters from the file name and keep the extension as it as. Any Command Line command or Powershell/Python or any other script for windows? Thanks.
Upvotes: 1
Views: 1239
Reputation: 126722
If the two files you have reside in the same directory then removing _ from the first file will work, but when you'll try to remove the dot from the second file it will fail cause it'll have the same name as the first one. Maybe that's an edge case, so here's the basic solution:
Get-ChildItem -Filter *.mkv | Rename-Item -NewName {($_.BaseName -replace '\.|_') + $_.Extension}
Upvotes: 3
Reputation: 2479
In PowerShell you can use Rename-Item with a script block that determines the new name.
dir -Recurse -Include *.mkv | Rename-Item -NewName { expression to determine new name }
The expression within the script block can use $_ to reference the current FileInfo object.
More concretely:
dir -Recurse -Include *.mkv | Rename-Item -NewName { $_.Name.Replace('_', ' ') }
Use Rename-Item -WhatIf until you get it right.
Upvotes: 2