Guest User

Untitled

a guest
Jul 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import gzip
  2. import sys,os
  3. import fnmatch
  4.  
  5. dirpath = ""
  6.  
  7. #use to decompress the selected file(s)
  8. for f in os.listdir(dirpath):
  9. if fnmatch.fnmatch(f, '*file*'):
  10. zipfile = gzip.open(dirpath + f, 'rb') # open the file
  11. data = zipfile.read() # get the decompressed data
  12. newfilepath = (dirpath + f + '.decompressed') # assuming the filepath ends with .bz2
  13. with open(newfilepath, 'wb') as new_file:
  14. new_file.write(data)# write a uncompressed file
  15. new_file.close()
  16. print "decompressed %s" % f
  17.  
  18. print "decompress files complete"
  19.  
  20. #use to copy multiple files to one merged file
  21. import os
  22. os.chdir('')
  23. os.system('copy *.decompressed file.json')
  24.  
  25. print "file merge complete"
  26.  
  27. #use to view X characters from beginning of file (quick validation)
  28. f = open('file.json', 'r')
  29. f.read(1000)
Add Comment
Please, Sign In to add comment