Hi there! My root folder contains multiple sub-directories each of which contains multiple *.json.bz2 files. My goal is to decompress the bz2 files and place them in the same sub-directories where they are. Using examples found online, I am trying to run the following code (please note two additional questions mentioned there):
---------------------------------------------------------------------------
IsADirectoryError Traceback (most recent call last)
<ipython-input-20-6e967e3c97bb> in <module>()
9 filepath = os.path.join(dirpath, filename)
10 newfilepath = os.path.join(dirpath, filename[:-4])
---> 11 with open(newfilepath, 'wb') as new_file, bz2.BZ2File(filepath, 'rb') as file:
12 for data in iter(lambda : file.read(100 * 1024), b''):
13 new_file.write(data)
IsADirectoryError: [Errno 21] Is a directory: '/Users/mymac/Documents/Jupyter/Twitter/05/.'
Please advise what I am doing wrong here. Thank you in advance!
import sys import os import bz2 from bz2 import decompress path = '/Users/mymac/Documents/Jupyter/Twitter/05' for subdir, dirs, files in os.walk(path): for filename in files: filepath = os.path.join(dirpath, filename) newfilepath = os.path.join(dirpath, filename[:-4]) # Remove ".bz2" in the end with open(newfilepath, 'wb') as new_file, bz2.BZ2File(filepath, 'rb') as file: for data in iter(lambda : file.read(100 * 1024), b''): new_file.write(data) #Question: how do I delete the the "*.json.bz2" after they are deompressed?However, it returns the following error message:
---------------------------------------------------------------------------
IsADirectoryError Traceback (most recent call last)
<ipython-input-20-6e967e3c97bb> in <module>()
9 filepath = os.path.join(dirpath, filename)
10 newfilepath = os.path.join(dirpath, filename[:-4])
---> 11 with open(newfilepath, 'wb') as new_file, bz2.BZ2File(filepath, 'rb') as file:
12 for data in iter(lambda : file.read(100 * 1024), b''):
13 new_file.write(data)
IsADirectoryError: [Errno 21] Is a directory: '/Users/mymac/Documents/Jupyter/Twitter/05/.'
Please advise what I am doing wrong here. Thank you in advance!