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
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.