I have about 1,500 folders where the last 4 digits represent a year. I need to add parenthesis around the year while preserving the rest of the name. The folder names vary in length from about 4 characters to over 20. Some of the folder names contain numbers other than the date.
I found a way to put a parenthesis at the end of the folder name. As well as a way to add a parenthesis at a certain place from the beginning of the name. But cannot seem to find a way to count backward from the end of the name.
Get-ChildItem -Directory | Rename-Item -NewName {$_.Name -replace '^' ,")"}
Get-ChildItem -Directory | % { $_ | Rename-Item -NewName ($_.Name -replace '^([\S\s]{5})', '$1(')}
I would like to take a folders like this:
Short.1990 Long.Folder.name.2019 Folder.1.1998
And end with folder names like this:
Short.(1990) Long.Folder.name.(2019) Folder.1.(1998)