For example
test-123-abc.mp4
test-456-def.mp4
I want to remove all after _
or -
. So the result should be:
123.mp4
456.mp4
Is it possible to use Windows cmd or a batch file, PowerShell to rename?
For example
test-123-abc.mp4
test-456-def.mp4
I want to remove all after _
or -
. So the result should be:
123.mp4
456.mp4
Is it possible to use Windows cmd or a batch file, PowerShell to rename?
I am assuming that all the file name are in the same format. This is just an example, you have to write the script yourself. If you are facing any issue, post the script.
Get-ChildItem -Path D:\Videos -File | Rename-Item -NewName { $_.Name -replace "Combo.*","Combo.mp4" }
Ex.
'test-123-abc.mp4' -replace '.*-(.*)-.*(\..*)','$1$2'
123.mp4
'test-456-def.mp4' -replace '.*-(.*)-.*(\..*)','$1$2'
456.mp4
'TRG-21-Aries Combo-JM5rowKV9TU.mp4' -replace 'Combo.*','Combo.mp4'
TRG-21-Aries Combo.mp4
It sounds like you want the rename to occur on all .mp4 files in the directory. If so, this might work. When you are satisfied that the files will be correctly renamed, remove the -WhatIf
from the Move-Item command.
Get-ChildItem -Filter *.mp4 |
ForEach-Object {
$newname = $_.Name -replace '(.*)[-_].*(\..*)','$1$2'
Rename-Item -Path $_.FullName -NewName $newname -WhatIf
}