Ranger Studios

RSS

Powershell Renaming Files with Incremental names

Here’s a handy little Windows Powershell script for renaming multiple files in a directory with an incremental number as part of the file name.

#------------------------------------------------------------------------#
#                                                                        #
# Script Name : renamePngs.ps1                                           #
#                                                                        #
# Author      : Ranger Studios                                           #
#                                                                        #
# Description : Rename .png files in a directory with unique names.      #
#                                                                        #
#------------------------------------------------------------------------#

                         #-----------------------------------------------#
                         # Variable Declarations.                        #
                         #-----------------------------------------------#

$currentLocation = get-location
$path            = $currentLocation.toString()
$files           = get-childitem $path *.png
$count           = 0

                         #-----------------------------------------------#
                         # Loop through files in path and rename.        #
                         #-----------------------------------------------#
foreach ($file in $files) 
{
    Rename-Item $file -NewName "hp_sc_$count.png";
    $count++;
}

#------------------------------------------------------------------------#
# -------------------------  End of Script  ---------------------------- #
#------------------------------------------------------------------------#