Python Forum
Rename file from value in text file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Rename file from value in text file (/thread-23805.html)



Rename file from value in text file - Nuge93 - Jan-17-2020

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.


RE: Rename file from value in text file - gruntfutuk - Jan-20-2020

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.