How to rename files from format xxxxxx-n-yyyyyy.ext to yyyyyy-n-xxxxxx.ext RRS feed

  • Question

  • Hello, scripting guys

    Is there any script that I can use to rename all files in a folder from xxxxxx-n-yyyyyy.ext to yyyyyy-n-xxxxxx.ext? 


    • Moved by Bill_Stewart Monday, January 7, 2019 8:18 PM This is not "scripts on demand"
    Tuesday, November 13, 2018 7:37 PM

All replies

  • Does the following help you?


    • Edited by Kamal Bhatt Tuesday, November 13, 2018 7:54 PM
    Tuesday, November 13, 2018 7:54 PM
  • In PowerShell? You'll need to make use of Get-ChildItem then pipe it to Rename-Item with the NewName being the result of applying replace operation -which makes use of regular expressions- on the current name. The exact regular expression will depend on what your scenario is, but here is an example that will replace a static string to get you started.

    'xxxxxx-n-yyyyyy.ext' -replace '^([^-]+)(-n-)([^\.]+)(\.ext)$' , '$3$2$1$4'

    • Edited by A'ziz Wednesday, November 14, 2018 7:44 AM fix regex
    Wednesday, November 14, 2018 7:43 AM