Bulk replace part filename

Copper Contributor

I have a lot of files with name like this "scmp_20200101_123456.jpg" I need to cut short the filename from the second '_' . Can anyone help.

 

Paul Cheuk.

2 Replies

If all the files have two underscores, then this command should rename them to the shorter format:

foreach ($file in Get-ChildItem -Path d:\temp -File) {Rename-Item -Path $file.fullname -NewName $file.fullname.split('_')[2]}

Did this work for you?