import os
import chardet
def convert\_to\_utf8(folder\_path):
for root, \_, files in os.walk(folder\_path):
for file in files:
if file.endswith(".cs"): # .cs 파일만 선택
file\_path = os.path.join(root, file)
with open(file\_path, 'rb') as f:
raw\_data = f.read()
detected = chardet.detect(raw\_data) # 인코딩 감지
encoding = detected\['encoding'\] if detected\['encoding'\] else 'utf-8'
if encoding.lower() != 'utf-8':
try:
text = raw\_data.decode(encoding)
with open(file\_path, 'w', encoding='utf-8') as f:
f.write(text)
print(f"Converted: {file\_path} from {encoding} to UTF-8")
except Exception as e:
print(f"Failed to convert {file\_path}: {e}")
else:
print(f"Skipped (already UTF-8): {file\_path}")
# 사용 예시
folder\_path = "C:/your/folder/path" # 변경 필요
convert\_to\_utf8(folder\_path)