Reputation: 1707
I am very new to powershell. I have a folder with multiple files, each file name is like:
File1_backup_2016_09_01_095444_1628350.bak
Need to rename all of them to Filex_yyyymmdd.bak
Upvotes: 0
Views: 2060
Reputation: 880
Something similar should works for you:
Get-ChildItem "C:\temp" |foreach {
$SplitName = $_.Name -split '_'
Rename-Item $_.FullName -NewName "$($SplitName[0])_$($SplitName[2])$($SplitName[3])$($SplitName[4]).bak"
}
Upvotes: 2