PowerShell: Bulk renaming File Names
You may want to rename thousands or millions of files within a folder with folder name as the prefix to them. Copy your folder path and paste it at <path of Folder> (we have also checked for .jpg and .png files).
Condition 1:
#script to add prefix(foldername) before each file name in a folder CD <path of Folder>
Get-ChildItem | Where-Object { $_.Extension -eq ".jpg" -or $_.Extension -eq ".png" -and !$_.Name.StartsWith($_.Directory.Name) } | rename-item -newname {$_.Directory.Name +" - " + $_.Name}
**Condition 2:
**
#script to add new prefix(CL -) before each file name in a folder CD <path of Folder>
Get-ChildItem | Where-Object { $_.Extension -eq ".jpg" -or $_.Extension -eq ".png"} | rename-item -newname {"CL - " + $_.Name}