In a personnel folder there are files regarding coaching for employees that were created by the persons supervisor. The naming convention for these files ALWAYS should be like
Supervisorname.SXXEXX.NameOfIssue.doc
So a breakdown further:
So a sample name would be Bob Godfrey.S48E99.Issue With Blue.doc - however, since some supervisors did not follow the rules there are files without the . seperator, we have files that look like
Bob Godfrey - S48E99 - Issue With Blue.doc
Bob Godfrey X S48E99 - Issue With Blue.doc
Bob Godfrey S48E99 - Issue With Blue.doc
For normalization purposes, (and for me not to pull my hair out in the process) I tried to use the below syntax to grab these outliers and rename them (there are roughly 300) now while this seems to execute as it should, the files are not renamed.
What do I need to change to get these files renamed accordingly?
Get-ChildItem -Path R:\Personnel\ -Filter *.doc |
Rename-Item -NewName { $_.BaseName.Replace(" - ", ".") + $_.Extension } -Verbose
Get-ChildItem -Path R:\Personnel\ -Filter *.doc |
Rename-Item -NewName { $_.BaseName.Replace(" X ", ".") + $_.Extension } -Verbose
Use a regular expression replacement to center your matches around the stipulation/employee number part of the filename:
Rename-Item -NewName { $_.Name -replace ' (?:[-X] )?(S\d\dE\d\d)(?: [-X])? ', '.$1.' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With