unzipfile.py 470 B

123456789101112131415161718192021222324252627
  1. import zipfile
  2. import os
  3. import time
  4. def unzipfile_and_remove(downloadFilePath, filename):
  5. filepath = downloadFilePath + "\\" + filename + ".zip"
  6. while not os.path.exists(filepath):
  7. time.sleep(1)
  8. if os.path.isfile(filepath):
  9. zip_ref = zipfile.ZipFile(filepath, "r")
  10. zip_ref.extractall(downloadFilePath)
  11. zip_ref.close()
  12. os.remove(filepath)
  13. else:
  14. raise ValueError("%s isn't a file!" % filepath)