I have been trying to add "Q3" to the beginning of 89 pdf files within one folder. I have managed to get results with the solution presented HERE
this works but only for roughly 10-15 files before it stops with a variety of errors it seems and without a defined order meaning the roughly 10-15 is different each time. i either receive a "FileNotFoundError: [WinError 2] The system cannot find the file specified:" or "PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:"
I understand the "permissionserror" is because the .py file I am working on and running is located in the same directory as the pdf files so it is running over this file. But putting it within the same directory was suggested in the above linked solution to solve the WinError2 and prior to doing so it would not do anything.
*first part of code is to delete some unwanted files that show up and may not be relevant to question
import os
my_dir = "DIRECTORY OF PDF FILES"
for fname in os.listdir(my_dir):
if fname.startswith('Copy') or fname.startswith('SxDI'):
os.remove(os.path.join(my_dir, fname))
for fname in os.listdir(my_dir):
os.rename(fname, "Q3" + fname)