I have a large number of files in a directory with this type of naming convention: "1050_14447_Letter Extension.pdf", etc. I need to remove all characters before the 2nd underscore (including the 2nd underscore). So the new file name would be "Letter Extension.pdf". How can I iterate the single directory renaming accordingly?
Here's an example to rename all pdf files in the current directory, removing all leading numbers or underscores from the file name:
Get-ChildItem -Filter *.pdf | Rename-Item -NewName {$_.Name -replace '^[0-9_]+'}
Here's another method that doesn't rely on regex but assumes no underscores in the filepath:
Get-ChildItem 'C:\path2files' | %{
Rename-Item $_.fullname $_.Name.Split("_")[2]
}
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