Asked by:
Renaming JPGs from name to code

Question
-
I've been asked to rename a folder full of staff photos from "Surname, Firstname" to their staff code. I have a CSV in the format of "staff_code,lastname,firstname" but have no clue on how to marry them together and bulk rename the files.
Any help would be appreciated :)
Monday, October 14, 2019 4:48 AM
All replies
-
You need to post your script with a question about your script.
Please read the following forum posting requirements and links to resources to learn how to write a script.
Please carefully review the following links to set your expectation for posting in technical forums.
- This Forum is for Scripting Questions Rather than script requests
- How to ask questions in a technical forum
- How to post code in Technet Forums
Learning to script properly with PowerShell
- Microsoft Script Gallery
- Getting Started with Microsoft PowerShell
- PowerShell Documentation
- The PowerShell Best Practices and Style Guide
\_(ツ)_/
Monday, October 14, 2019 5:07 AM -
You need to post your script with a question about your script.
Please read the following forum posting requirements and links to resources to learn how to write a script.
Please carefully review the following links to set your expectation for posting in technical forums.
Monday, October 14, 2019 5:22 AM -
Hi,
Thanks for your question.
You can use "get-childitem" cmdlet to get the staff photos. And use if statement to determine the matching file name, then use "rename-item" cmdlet to rename it.
For example:
$files=Get-ChildItem -Path "C:\test\" $csvs=Import-Csv -Path "C:\aa.csv" foreach ($file in $files) { foreach($csv in $csvs) { if ($file.basename -eq "$($csv.lastname),$($csv.firstname)") { Rename-Item $file.fullname -NewName "$($csv."staff_code")$($file.extension)" } } }
Best regards,
Lee
Just do it.
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Friday, November 8, 2019 1:59 PM
Monday, October 14, 2019 7:13 AM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
LeePlease remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.Friday, November 8, 2019 2:00 PM