Python Forum

Full Version: Rename file from value in text file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I have a number of pdf files currently named with my Employee's Names, in the format of "last, first", that need to be renamed with their employee number.

I've created a text file that has 2 columns. The first column has the employee's names, in the same "last, first" format, descending alphabetically, so that it's identical to the file names. In the second column is the employee's number. What I'm hoping to do is create script that will look at the filename, match it to the same value in column A, and then rename the file with the employee number in column B.

The closest thing I've seen to my issue is here Thanks for any advice/help you can provide.
So where exactly are you stuck?

Use pathlib to handle the filenames, loop through the list of employee names and for each name, rename the file to the corresponding new filename. Use try/except block to trap and handle specific exceptions.

You need to provide some pseudo code at least for us to help you with.