2

want to delete pdf files from the directory using python. Having "pdffiles" name folder in that lost of pdf are there So I want to delete all files from it but don't want to delete folder, want to delete just file from folder. how can I do it.(may be using os.remove())

psw
  • 45
  • 1
  • 9

1 Answers1

4

Try listdir+remove:

import os
for i in os.listdir('directory path'):
    if i.endswith('.pdf'):
        os.remove(i)
U13-Forward
  • 69,221
  • 14
  • 89
  • 114