Your Ad Here

Posted By

cieux-gris on 09/03/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

carlosabargues


Contains archive


 / Published in: Python
 

Given a directory path, return true if the directory contains at least one type of archive file, as specified in the list of archive extensions. Otherwise, return false. This version uses lower() to help comparison in situations where capitalization may be different.

  1. def containsArchive (dirPath):
  2. contents=os.listdir(dirPath)
  3. archiveExts=['.zip','.rar','.gz','.bz2','.tar','.r01','.r001']
  4. archiveList=[item for item in contents if os.path.splitext(item)[-1].lower() in archiveExts]
  5. return not archiveList==list()

Report this snippet  

You need to login to post a comment.