Search This Blog

Thursday, July 11, 2013

Powershell – how to renumber files sequentially

Sourced from  http://justanothersysadmin.wordpress.com/2008/03/22/bulk-rename-files-with-sequential-index/

here is how to use powershell to renumber files sequentially.. be careful not to renumber files you don’t want renumbered!! Best to move all the files to a new temp folder to do this….

1) copy paste as single line into powershell

function Rename-Bulk($prefix){$files = Get-ChildItem;$id = 1;$files | foreach { Rename-Item -Path $_.fullname -NewName ( $prefix + ((($id++).tostring()).padleft(($files.count.tostring()).length) -replace ' ','0' ) + $_.extension) }}

2) CD to folder in powershell

3)  Rename-Bulk('img')   where img is the prefix for all output with sequential number following

No comments: