I have a bunch of files in a directory. They are automatically downloaded with the following names:
new.pdb
new(1).pdb
new(2).pdb and so on
I have a list of the actual filenames like:
AAA
BBB
CCC
I want a way to rename the files with their corresponding names in the list where new.pdb would be AAA.pdb, new(1).pdb would be BBB.pdb and so on. I'd really appreciate if you could give me a hint before you down vote. I've tried well enough to solve this but couldn't. I've tried this so far. But the issue with the following code is that a few files may download faster than the ones that started before them. So it doensn't rename as I wanted.
infiles = filter(os.path.isfile, os.listdir(os.getcwd()))
infiles = [os.path.join(os.getcwd(), f) for f in infiles]
infiles.sort(key=lambda x: os.path.getmtime(x))
last_file = infiles[-1]
if rename_files.endswith(".pdb"):
os.rename(last_file, directory_name+".pdb")
last_file = infiles[-1]then you try to loop over that single path withfor rename_files in last_file:I think this is not doing what you describe in the text of your question.