I'm a beginner in Python and I'm trying to solve the below problem. Is it possible to access files in subdirectories in Python, while numerating subdirectories? one json file that I'm accessing corresponds to one football game. Currently, I'm just iterating through files and numerating games:
directory = '/Users/James/Downloads/JSON_TestData/JSONFirstRound'
game_id = 0
for path in glob.iglob(f'{directory}/*.json'):
with open(path, encoding= "latin-1") as json_file:
data = json.load(json_file)
game_id += 1
So, here I'm using just JSONFirstRound subfolder and game_id increasing for each json file loaded. My goal is to access JSONFirstRound in /Users/James/Downloads/JSON_TestData, define round_id = 1, access each json file in JSONFirstRound and then switch to JSONSecondRound in the same directory, define round_id = 2, access each json file in JSONSecondRound and so on ... I would access subdirectories, I'm currently confused how I can numerate them using glob. Thank you.