Guest User

Untitled

a guest
Aug 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/usr/bin/python
  2. import os, zipfile, pyunpack
  3. basis_folder = r'C:\Users\ssv\Documents\tmp'
  4.  
  5. for root, dirs, files in os.walk(basis_folder):
  6. for filename in files:
  7. if filename.endswith(".rar") :
  8. print('RAR:'+os.path.join(root,filename))
  9. elif filename.endswith(".zip"):
  10. print('ZIP:'+os.path.join(root,filename))
  11. name = os.path.splitext(os.path.basename(filename))[0]
  12. if filename.endswith(".rar") or filename.endswith(".zip"):
  13. try:
  14. arch = pyunpack.Archive(os.path.join(root,filename))
  15. # os.mkdir(name)
  16. arch.extractall(directory=root)
  17. os.remove(os.path.join(root,filename))
  18. except Exception as e:
  19. print("ERROR: BAD ARCHIVE "+os.path.join(root,filename))
  20. print(e)
  21. try:
  22. # os.path.join(root,filename)os.remove(filename)
  23. pass
  24. except OSError as e: # this would be "except OSError, e:" before Python 2.6
  25. if e.errno != errno.ENOENT: # errno.ENOENT = no such file or directory
  26. raise # re-raise exception if a different error occured
Add Comment
Please, Sign In to add comment