Remove additional file extensions from filenames

See here for the original answer.

What I recommend is running a regex to remove .pdf when the name string ends with it, like so:

if pdf_checker(name):
    newName = re.sub(r'\.pdf$', '.txt', name)
    convert_pdf_to_txt(name, newName)

Then replace this line:

make_new_text_file = open(text_folder_path + '/' + path + '.txt', 'w')

With the following:

make_new_text_file = open(text_folder_path + '/' + txtname, 'w')

Tags

  1. regex (Private)
  2. python (Private)
  3. stack-overflow (Private)
  4. answer (Private)