1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import json
# 主目录路径
main_directory = f'{os.path.join(os.path.abspath("../"), "network-assets-reptile", "reptile_data")}'
# 初始化总长度
total_length = 0
# 遍历主目录下的子目录
for root, dirs, files in os.walk(main_directory):
for dir_name in dirs:
dir_path = os.path.join(root, dir_name)
for roots, path, file in os.walk(dir_path):
for dis in path:
json_file_path = os.path.join(os.path.join(roots,dis), 'data.json')
# 检查data.json文件是否存在
if os.path.exists(json_file_path):
with open(json_file_path, 'r', encoding='utf-8') as json_file:
try:
# 读取JSON数组
json_data = json.load(json_file)
# 统计JSON数组的长度,并累加到总长度
array_length = len(json_data)
total_length += array_length
# print(f"Found {array_length} entries in {json_file_path}")
except json.JSONDecodeError:
# print(f"Error parsing JSON in {json_file_path}")
error = 0
else:
# print(f"Could not find data.json in {dir_path}")
error = 0
print(f"总数据量: {total_length}")