Forum Discussion
Paul_Cheuk
May 31, 2021Copper Contributor
Bulk replace part filename
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.
Jan 29, 2022
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]}