The 1st time, only one file was renamed, but no error message. The 2nd time, an error message popped up, as shown in the screenshot, which is expectable
Here's a solution in Python. It will work with different operating systems (Windows, Linux, MacOS, etc.). Make sure the script is in the same directory as the files you want to rename.
Python code (script.py)
import os
import sys
with open(sys.argv[1]) as fh:
for line in fh:
sl = line.strip().split(",")
old_name = sl[0]
new_name = sl[1]
os.rename(old_name, new_name)
How to use
python script.py input.txt
Input.txt
ABCD123QW.txt,AL001.txt
ABCD345XB.txt,AL002.txt
Demo
Look at the screenshot of my terminal on Mac. First I display all files that are in the directory (ABCD123QW.txt, ABCD345XB.txt, input.txt, script.py). Then, I run the script and list files again. You can see that two text files were renamed to AL001.txt and AL002.txt.
Python scripts need to be executed from the command prompt (under Windows) or terminal (under Linux/MacOs). The prompt >>> indicates that you are now in an interactive Python interpeter session, also called the “Python shell”. This is different from the normal terminal command prompt.
If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted. You can accept multiple answers as correct.
Can you share error you are getting or first few lines of the csv file you are using, the script working perfectly fine in my computer with multiple file name as input.
The 1st time, only one file was renamed, but no error message. The 2nd time, an error message popped up, as shown in the screenshot, which is expectable
I don't know why it didn't work in your computer here I attached a GIF Animation.
The Screenshot:
Please use
ADD COMMENT/ADD REPLY
when responding to existing posts to keep threads logically organized.All of your comments regarding
bash
script should have gone under @Arup's answer.