Tuesday, December 26, 2017

batch rename - Bulk Folder Renaming Powershell Script

The script below is used for Bulk Folder Renaming.


However I wanted to make this as a Generic Script so users can give input and use it accordingly.



  1. This script has 3 inputs

    • a) Enter the Source Folder path

    • b) Extension of the Files and

    • c) New File Name to be renamed



All are fine except the c) New File Name to be renamed


$Rename = input
$newName = '$Rename_{0:d6}{1}' -f $i , $extension # $rename input cannot be used here #

I think some thing wrong on the above line, is there any way to get this done?


Write-Host "Renaming Bulk Files" -BackgroundColor Green -ForegroundColor White
$Source = Read-Host "Enter the Source Path Of the Folder, Ex: D:\Test"
$SourceExtension = Read-Host "Enter the Destination File Extension, Ex: *.pdf or *.jpg"
$Rename = Read-Host "Enter the File Name to be renamed"
$i = 0
Get-ChildItem -Path $Source -Filter $SourceExtension |
ForEach-Object {
$extension = $_.Extension
$newName = '$Rename_{0:d6}{1}' -f $i , $extension
$i++
Rename-Item -Path $_.FullName -NewName $newName
}

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...