2025-02-03 16:08:12 +09:00
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import unicodedata
|
|
|
|
|
|
2025-02-15 17:00:21 +09:00
|
|
|
def copy_dic_subdirs(source_root, target_root_a, target_root_b, target_root_c, target_root_d):
|
2025-02-03 16:08:12 +09:00
|
|
|
for root, dirs, files in os.walk(source_root):
|
|
|
|
|
for dir_name in dirs:
|
2025-02-15 17:00:21 +09:00
|
|
|
if dir_name == 'DIW': # DIC 디렉토리 탐색
|
2025-02-03 16:08:12 +09:00
|
|
|
parent_dir = os.path.basename(os.path.dirname(os.path.join(root, dir_name)))
|
|
|
|
|
target_root = None
|
|
|
|
|
parent_dir = unicodedata.normalize('NFC', parent_dir)
|
|
|
|
|
|
|
|
|
|
# 부모 디렉토리가 '2교시'인지, '3교시'인지 확인
|
2025-02-15 17:00:21 +09:00
|
|
|
if parent_dir == '1교시':
|
|
|
|
|
target_root = target_root_a
|
|
|
|
|
elif parent_dir == '2교시':
|
2025-02-03 16:08:12 +09:00
|
|
|
target_root = target_root_b
|
|
|
|
|
elif parent_dir == '3교시':
|
|
|
|
|
target_root = target_root_c
|
2025-02-15 17:00:21 +09:00
|
|
|
elif parent_dir == '4교시':
|
|
|
|
|
target_root = target_root_d
|
2025-02-03 16:08:12 +09:00
|
|
|
|
|
|
|
|
if target_root:
|
|
|
|
|
source_dic_path = os.path.join(root, dir_name)
|
|
|
|
|
target_dic_path = os.path.join(target_root, dir_name)
|
|
|
|
|
|
|
|
|
|
# DIC 하위 디렉토리와 파일 복사
|
|
|
|
|
shutil.copytree(source_dic_path, target_dic_path, dirs_exist_ok=True)
|
|
|
|
|
print(f"Copied {source_dic_path} to {target_dic_path}")
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
print(f"Skipping {dir_name} under {parent_dir}, as it doesn't match '2교시' or '3교시'.")
|
|
|
|
|
|
|
|
|
|
# 사용법
|
2025-02-15 17:00:21 +09:00
|
|
|
source_directory = r"C:\Users\dra\project\data\제2521회 특별검정\제2521회 디지털정보활용능력 특별검정 답안파일" # 원본 디렉토리 경로
|
|
|
|
|
target_directory_a = r".\output\A" # '2교시'의 타겟 경로
|
2025-02-04 12:01:07 +09:00
|
|
|
target_directory_b = r".\output\B" # '2교시'의 타겟 경로
|
|
|
|
|
target_directory_c = r".\output\C" # '3교시'의 타겟 경로
|
2025-02-15 17:00:21 +09:00
|
|
|
target_directory_d = r".\output\D" # '3교시'의 타겟 경로
|
2025-02-03 16:08:12 +09:00
|
|
|
|
2025-02-15 17:00:21 +09:00
|
|
|
copy_dic_subdirs(source_directory, target_directory_a, target_directory_b, target_directory_c, target_directory_d)
|