Skip to content

Commit 847766b

Browse files
committed
Added simple python-script to exctract tar files containing multiple json files with the same name, related to #7
1 parent 5eca5e2 commit 847766b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

controller/extractTarFiles.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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

0 commit comments

Comments
 (0)