Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. import tarfile
  2. import os
  3. from glob import glob
  4. import sys
  5.  
  6. with tarfile.open(sys.argv[1]) as tar:
  7. for f in tar:
  8. name = f.name[:-5]
  9. if os.path.isfile(name + "#001.json"):
  10. index = len(glob(name + "*")) + 1
  11. newName = name + "#%03d.json" % index
  12. else:
  13. newName = name + "#001.json"
  14. tar.extract(f)
  15. os.rename(f.name, newName)
  16. print newName
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement