Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gzip
- import sys,os
- import fnmatch
- dirpath = ""
- #use to decompress the selected file(s)
- for f in os.listdir(dirpath):
- if fnmatch.fnmatch(f, '*file*'):
- zipfile = gzip.open(dirpath + f, 'rb') # open the file
- data = zipfile.read() # get the decompressed data
- newfilepath = (dirpath + f + '.decompressed') # assuming the filepath ends with .bz2
- with open(newfilepath, 'wb') as new_file:
- new_file.write(data)# write a uncompressed file
- new_file.close()
- print "decompressed %s" % f
- print "decompress files complete"
- #use to copy multiple files to one merged file
- import os
- os.chdir('')
- os.system('copy *.decompressed file.json')
- print "file merge complete"
- #use to view X characters from beginning of file (quick validation)
- f = open('file.json', 'r')
- f.read(1000)
Add Comment
Please, Sign In to add comment