Search code examples
powershelldirectoryrenamefile-rename

Replace one character in front of text in file name powershell


I am trying to rename a big batch of folders with powershell.

I have the folders in this format:

2009.10.11.Name

and I want to change that to:

2009.10.11 Name

I cant find a working way to just target the . in front of the Name. Pleas help


Solution

  • Use the -replace regex operator:

    Get-ChildItem . -Directory |Rename-Item -NewName {$_.Name -replace '(?<=^\d{4}\.\d\d\.\d\d)\.',' '}