Batch Rename Files With Powershell

From Littledamien Wiki
Jump to navigation Jump to search

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 -recurse argument can be applied to the gci command.

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]