Batch Rename Files With Powershell
Filtering files[edit]
Use Get-ChildItem aka gci.
> Get-ChildItem -filter "*needle*"
- ("needle" in the example above is the string to match in the file names.
- The
-recurseargument can be applied to thegcicommand.
Using regular expressions to filter files[1][edit]
> Get-ChildItem | Where-Object {$_.name -match "p-\d{2}.jpg"}
Renaming the files[2][edit]
> Get-ChildItem | Where-Object {$_.name -match "p-\d{2}.jpg"} | Rename-Item -NewName {$_.name -replace "p-", "newname-"}
Notes[edit]
- ↑ Filtering Collections with Regular Expressions (Microsoft TechNet)
- ↑ Use Powershell to Rename Files in Bulk (TechNet Blogs)