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 can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 12 28,143 Feb-13-2025, 04:48 AM
Last Post: tomhansky
  How to write variable in a python file then import it in another python file? tatahuft 4 953 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  Problems writing a large text file in python Vilius 4 1,024 Dec-21-2024, 09:20 AM
Last Post: Pedroski55
  Get an FFMpeg pass to subprocess.PIPE to treat list as text file? haihal 2 1,056 Nov-21-2024, 11:48 PM
Last Post: haihal
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,085 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 974 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  rename same file names in different directories elnk 5 2,450 Jul-12-2024, 01:43 PM
Last Post: snippsat
  Extract and rename a file from an Archive tester_V 4 3,777 Jul-08-2024, 07:54 AM
Last Post: tester_V
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 6,462 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  Reading an ASCII text file and parsing data... oradba4u 2 1,461 Jun-08-2024, 12:41 AM
Last Post: oradba4u

Forum Jump:

User Panel Messages

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