1

i am looking for a way to remove (file-number) part from file name (file-number).extension and put number in front of file name before a underline. so new pics (1).jpg will be renamed to 1_new pics.jpg

i have tried ls | rename-item -newname {$_ -replace '(.*) ((\d+)).(.*)', '$2_$1.$3'}but i couldnt find a working one

1
  • 1
    A man had a problem. He used regular expressions. Now he has two problems.
    – juhist
    Commented Feb 23, 2019 at 10:25

1 Answer 1

0

This did it for me:

ls | Rename-Item -NewName {$_ -replace '(.*)\((\d+)\)\.(.*)', '$2_$1.$3' }
1
  • ls | rename-item -newname {$_ -replace '(.*) \((\d+)\).(.*)', '$2_$1.$3' } this one removes space between filename and extension in output
    – ahmad
    Commented Feb 23, 2019 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .