-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmerge.py
More file actions
21 lines (17 loc) · 737 Bytes
/
Copy pathmerge.py
File metadata and controls
21 lines (17 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
import json
def merge_json_files(directory):
merged_data = []
# Loop through each subdirectory and file in the main directory
for subdir, _, files in os.walk(directory): # Check if the subdirectory starts with 'abc'
for file in files:
if file.endswith(".json"):
with open(os.path.join(subdir, file), 'r') as f:
data = json.load(f)
merged_data.append(data)
# Save merged data to a new JSON file
with open("output/medium_harm/eval_mid_harm.json", "w") as f:
json.dump(merged_data, f, indent=4)
if __name__ == "__main__":
main_directory = './harm_results_mid'
merge_json_files(main_directory)