| import os | |
| import json | |
| import subprocess | |
| import os | |
| import json | |
| # PLY 파일들이 들어 있는 폴더 경로 | |
| folder = "./dataset" | |
| # 분류할 카테고리를 미리 정의합니다. | |
| categories = ["100", "75", "50", "25", "0"] | |
| # 결과를 저장할 딕셔너리를 카테고리별로 초기화합니다. | |
| grouped_files = {cat: [] for cat in categories} | |
| # 확장자가 .ply 인 파일 목록을 가져옵니다. | |
| try: | |
| all_files = os.listdir(folder) | |
| except FileNotFoundError: | |
| print(f"오류: '{folder}' 폴더를 찾을 수 없습니다.") | |
| all_files = [] | |
| # 각 파일을 순회하며 적절한 카테고리에 추가합니다. | |
| for filename_with_ext in all_files: | |
| if filename_with_ext.endswith(".ply"): | |
| # 확장자(.ply)를 제거합니다. | |
| filename = filename_with_ext.removesuffix('.ply') | |
| # 파일명을 '_' 기준으로 분리하여 접두어(prefix)를 얻습니다. | |
| prefix = filename.split('_')[0] | |
| # 접두어가 정의된 카테고리 중 하나라면, 해당 리스트에 파일명을 추가합니다. | |
| if prefix in grouped_files: | |
| grouped_files[prefix].append(filename) | |
| # 분류된 딕셔너리를 JSON 파일로 저장합니다. | |
| with open("ply_files.json", "w", encoding="utf-8") as f: | |
| json.dump(grouped_files, f, ensure_ascii=False, indent=2) | |
| print("JSON 저장 완료! 아래와 같이 파일이 분류되었습니다.") | |
| print(json.dumps(grouped_files, indent=2)) | |
| # merged.py 실행 | |
| subprocess.run(["python3", "merged.py"]) |