Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to rename multiple files that follow the same naming convention, the only variation is the date at the end of the name.

For example TRADARCASHROLLUP.GRPTIRHK.01052017.CSV I would like the new name of the file to begin with the date instead 01052017.TRADARCASHROLLUP.GRPTIRHK.CSV

Was hoping someone could help me write a batch script to achieve this. I have seen other answers but not been able to apply them to this.

I have tried using the following:

ls | %{ "C:UBSTestingIncomingTRADARCASHROLLUP.GRPTIRHK*" $_.name ($_.name 
-replace '^(w+).(w+).(w+)', '$3.$1.$2')}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
206 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try with this code :

Get-ChildItem -Path 'C:	emp' | ForEach-Object {
    $newName = $_.Name -replace '(.+).(d{8})', '$2.$1'
    Rename-Item $_ -NewName $newName
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...