Your Ad Here

Posted By

cieux-gris on 09/03/08


Tagged


Versions (?)

Contains exactly one pdf


 / Published in: Python
 

Given a directory path, return true if the directory contains exactly one pdf file. Using lower() to circumvent capitalization issues.

  1. def containsExactlyOnePdf (dirPath):
  2. contents=os.listdir(dirPath)
  3. pdfExts=['.pdf']
  4. pdfList=[item for item in contents if os.path.splitext(item)[-1].lower() in pdfExts]
  5. return len(pdfList)==1

Report this snippet  

You need to login to post a comment.