Rename multiple files with powershell

From DevOps Notebook
Revision as of 10:38, 31 January 2023 by MilosZ (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Example:
Rename files named image.1.jpg, image.3.jpg... into 1.jpg, 3.jpg

Get-ChildItem image.*.jpg|ForEach-Object {
    $NewName = $_.Name -replace "^(image\.)(.*)",'$2'
    $Destination = Join-Path -Path $_.Directory.FullName -ChildPath $NewName
    Move-Item -Path $_.FullName -Destination $Destination -Force
}