Skip to content

Instantly share code, notes, and snippets.

@fredrike
Created February 9, 2016 09:56
Show Gist options
  • Save fredrike/cf6c1fa66e7573d5568d to your computer and use it in GitHub Desktop.
Save fredrike/cf6c1fa66e7573d5568d to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment