thotwielder
thotwielder

Reputation: 1707

powershell rename all files in a folder to a pattern

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

Answers (1)

autosvet
autosvet

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])$($SplitNa‌​me[4]).bak"
}

Upvotes: 2

Related Questions