Welcome to Shaun Luttin's public notebook. It contains rough, practical notes. The guiding idea is that, despite what marketing tells us, there are no experts at anything. Sharing our half-baked ideas helps everyone. We're all just muddling thru. Find out more about our work at bigfont.ca.

Rename all files in a directory, and add a counter to each name.

Tags: powershell

Without Aliases

Get-ChildItem | 
ForEach-Object -Begin { $i = 0 } -Process 
{
Rename-Item -Path $_ -NewName ("someNewName-" + $i + $.Extension); $i++; }

With Aliases

dir | % -b { $i = 0 } { rni $ -new ("someNewName-" + $i + $_.Extension); $i++; }

If you're working with JPEGS, the result will look something like this:

someNewName-0.jpg
someNewName-1.jpg
someNewName-2.jpg
someNewName-3.jpg
someNewName-4.jpg
someNewName-5.jpg
someNewName-6.jpg
someNewName-7.jpg
someNewName-8.jpg
someNewName-9.jpg

See also: