Sunday 17 November 2013

File Names Renaming- Powershell

It is easier to change multiple files names within a folder through Powershell.



You may want to rename thousands or millions of files within a folder with Folder name as prefix to them. Copy your folder URL and paste it at <URL of Folder>(we have also checked .jpg and .png files)

Condition 1:

#script to add prefix(foldername) before each file name in a folder
CD <URL 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 <URL of Folder>

Get-ChildItem | Where-Object { $_.Extension -eq ".jpg" -or $_.Extension -eq ".png"} | rename-item -newname {"CL - " + $_.Name}

No comments:

Post a Comment