This content originally appeared on DEV Community and was authored by Stokry
Today I will show you a simple way to bulk rename your pdf files. If you have a group of PDFs that need to be copied and renamed for multiple folders this script will help you a lot.
Let's jump to the code.
import os
import shutil
from datetime import date
from os import walk
after importing we need to define the path:
mypath = r'C:\Users\Stokry\Desktop\python\bulk\main'
the we need to get files to rename:
_, _, filesnames = next(walk(mypath))
files will be copied into folders name John
and Anna
:
list = ['John', 'Anna']
also, we will set a current date
today = date.today().strftime("%m_%d_%y")
then we can create the new folders:
for name in list:
newdir = name + '_' + today
path = os.path.join(mypath, newdir)
os.mkdir(path)
this will copy the files:
for file in filesnames:
shutil.copy(mypath + '\\' + file, path)
os.rename(path + '\\' + file, path + '\\' + name + '' + file)
This is our final result:
Thank you all.
This content originally appeared on DEV Community and was authored by Stokry

Stokry | Sciencx (2021-06-10T09:34:34+00:00) How to bulk rename PDFs with Python. Retrieved from https://www.scien.cx/2021/06/10/how-to-bulk-rename-pdfs-with-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.