Mar-29-2017, 04:51 PM
You could .enumerate() os.walk() and files, but that might just make your code hard to read (and your counter would skip a few, so you'd have 1.json, then a 3.json without a 2). Here's how I'd do it, nice and simple:
for dirpath, dirname, files in os.walk('/Users/mymac/Documents/Jupyter/Twitter/1 day test'): file_counter = 0 for filename in files: if filename.endswith('.json.bz2'): filepath = os.path.join(dirpath, filename) file_counter += 1 newfilepath = os.path.join(dirpath, "{0}.json".format(file_counter))