Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 500
James World Avatar asked Sep 06 '12 09:09

James World


1 Answers

One simple solution is to run rename-item with -WhatIf. This will display something like

PS H:\test> gci | rename-item -newname { $_.name -replace 'temp','test' } -WhatIf
What if: Performing operation "Rename File" on Target "Item: H:\test\temp1 Destination: H:\test\test1".

Good enough, or do you need it to do it while also doing the operation?

EDIT: An even simpler solution, use -Verbose. Does the same as the -WhatIf, but also performing the operation :)

like image 118
carlpett Avatar answered Nov 10 '22 02:11

carlpett