Python Forum
Rename file from value in text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rename file from value in text file
#1
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.
Reply
#2
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.
I am trying to help you, really, even if it doesn't always seem that way
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 756 Apr-18-2024, 07:07 AM
Last Post: Bronjer
  very newbie problem on text file zapad 2 213 Apr-12-2024, 06:50 PM
Last Post: zapad
  Rename first row in a CSV file James_S 3 583 Dec-17-2023, 05:20 AM
Last Post: James_S
  file open "file not found error" shanoger 8 1,122 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Replace a text/word in docx file using Python Devan 4 3,364 Oct-17-2023, 06:03 PM
Last Post: Devan
  Need to replace a string with a file (HTML file) tester_V 1 763 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 926 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  save values permanently in python (perhaps not in a text file)? flash77 8 1,228 Jul-07-2023, 05:44 PM
Last Post: flash77
  rename file RolanRoll 0 532 May-18-2023, 02:17 PM
Last Post: RolanRoll
  '' FTP '' File upload with a specified string and rename midomarc 1 1,158 Apr-17-2023, 03:04 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020