Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- with open('data.json', 'r') as f:
- data = json.load(f)
- target = 'files/pasta-1/testes.html'
- def find_target(target, data, current_path=''):
- for item in data:
- if item['type'] == 'file' and f'{current_path}/{item["name"]}' == target:
- return item
- else:
- if item.get('items', []):
- if current_path:
- current_path = f'{current_path}/{item["name"]}'
- else:
- current_path = f'{item["name"]}'
- return find_target(
- target, item['items'], current_path=current_path)
- return None
- print(find_target(target, [data]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement