Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tarfile
- import os
- from glob import glob
- import sys
- with tarfile.open(sys.argv[1]) as tar:
- for f in tar:
- name = f.name[:-5]
- if os.path.isfile(name + "#001.json"):
- index = len(glob(name + "*")) + 1
- newName = name + "#%03d.json" % index
- else:
- newName = name + "#001.json"
- tar.extract(f)
- os.rename(f.name, newName)
- print newName
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement