Difference between revisions of "Rename multiple files with powershell"
From DevOps Notebook
(Created page with "Example:<br> Rename files named image.1.jpg, image.3.jpg... into 1.jpg, 3.jpg <br> <pre> <pre> Get-ChildItem image.*.jpg|ForEach-Object { $NewName = $_.Name -replace "^(i...") |
(No difference)
|
Revision as of 18:21, 7 June 2020
Example:
Rename files named image.1.jpg, image.3.jpg... into 1.jpg, 3.jpg
<pre>
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
}