Alex Rivera | Logout

In powershell, how can I use Rename-Item to output the old and new file names at the same time?

Asked 2012-09-06T09:44:33.917
9

I'd like to select a list of files using Get-ChildItem piped to Rename-Item and have the output display text with each line showing something like "Renamed oldfilename to newfilename".

How can I do this?

Edit
Report

1 Answer

11
Get-Childitem C:\Temp |
    Foreach-object {
        $OldName = $_.name; 
        $NewName = $_.name -replace 'temp','test'; 
        Rename-Item -Newname $NewName; 
        Write-Output $("Renamed {0} to {1}" -f $OldName,$NewName)
        }
answered 2012-09-06T15:17:44.750

Your Answer