Skip to content

Instantly share code, notes, and snippets.

@ConradMearns
Created February 12, 2020 04:51
Show Gist options
  • Save ConradMearns/5ab8c8cdd7d0bec5bf6588ed7b443803 to your computer and use it in GitHub Desktop.
Save ConradMearns/5ab8c8cdd7d0bec5bf6588ed7b443803 to your computer and use it in GitHub Desktop.
import os
# Get list of files to rename
files = os.listdir('.')
files = filter(lambda x: x.endswith('pdf'), files)
import pdftotext
for f in files:
fdat = ""
with open(f, 'rb') as pf:
fdat = pdftotext.PDF(pf)
fdat = fdat[0].split('\n')[0].strip().replace(' ', '').replace(':','').replace('/', '')
#print(fdat)
os.rename(f, fdat+'.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment