using System; using System.Collections.Generic; using System.IO; using System.Linq;…
- User
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions;
public class ProjectFileOrganizer { // 수정된 폴더 구조 정의 private static readonly Dictionary<string, string[]> FolderStructure = new Dictionary<string, string[]> { ["00_계약관련"] = new[] { "001 계약서", "002 과업지시서", "003 산출내역서", "004 과업수행계획서", "005 착수계" }, ["01_보고관련"] = new string[] { }, // 착수/중간/최종 보고회 자료 ["02_회의 및 검토자료"] = new string[] { }, // 업무협의, 기술검토 등 ["03_최종성과품"] = new[] { "031 보고서", "032 구조계산서", "033 설계서", "034 시방서", "035 수량산출서", "036 설계도면", "037 외주보고서" }, ["03_최종성과품/031 보고서"] = new[] { "표지및간지", "부록" }, ["03_최종성과품/033 설계서"] = new[] { "내역서" }, ["03_최종성과품/037 외주보고서"] = new[] { "0381 기상자료", "0382 측량보고서", "0383 수치보고서", "0384 해역이용협의서" }, ["04_행정관련"] = new[] { "041 외주관련", "042 기성관련", "043 준공관련", "044 공문", "045 기타" }, ["04_행정관련/044 공문"] = new[] { "0441 발송공문", "0442 수신공문" }, ["05_미분류"] = new string[] { } };
// 수정된 키워드 기반 분류 규칙 private static readonly Dictionary<string, List<string>> ClassificationRules = new Dictionary<string, List<string>> { // 00_계약관련 - 계약 및 사업 시작 관련 문서 ["00_계약관련/001 계약서"] = new List<string> { "계약서", "본계약", "변경계약", "부속합의서", "계약체결", "계약문서", "용역계약서" }, ["00_계약관련/002 과업지시서"] = new List<string> { "과업지시서", "RFP", "제안요청서", "과업범위", "과업내용", "사업지시서" }, ["00_계약관련/003 산출내역서"] = new List<string> { "산출내역서", "계약내역", "입찰내역", "예정가격", "원가계산서" }, ["00_계약관련/004 과업수행계획서"] = new List<string> { "과업수행계획", "실행계획", "수행계획서", "사업수행계획" }, ["00_계약관련/005 착수계"] = new List<string> { "착수계", "착수신고", "착수보고", "착수일", "사업착수" }, // 01_보고관련 - 공식 보고회 자료 (착수/중간/최종) ["01_보고관련"] = new List<string> { "착수보고회", "착수보고서", "착수발표", "중간보고회", "중간보고서", "중간발표", "최종보고회", "최종보고서", "최종발표", "보고회자료", "보고PPT", "보고회의록", "보고회결과" }, // 02_회의 및 검토자료 - 공식 보고 외 회의/검토 ["02_회의 및 검토자료"] = new List<string> { "회의록", "회의자료", "검토의견", "질의응답", "기술검토", "검토회", "협의결과", "업무협의", "내부회의", "외부회의", "실무회의", "자문회의", "아이디어회의", "브레인스토밍", "워크샵" }, // 03_최종성과품 - 프로젝트 최종 결과물 ["03_최종성과품/031 보고서"] = new List<string> { "최종보고서", "종합보고서", "본보고서", "완료보고서", "기본설계보고서", "실시설계보고서", "타당성보고서" }, ["03_최종성과품/031 보고서/표지및간지"] = new List<string> { "표지", "간지", "목차", "요약문", "제출문" }, ["03_최종성과품/031 보고서/부록"] = new List<string> { "부록", "부속자료", "별책", "참고자료", "첨부자료" }, ["03_최종성과품/032 구조계산서"] = new List<string> { "구조계산", "안정성검토", "구조해석", "구조검토", "수리계산", "수문계산", "하천계산", "홍수위계산" }, ["03_최종성과품/033 설계서"] = new List<string> { "설계서", "설계도서", "설계설명서", "설계보고서" }, ["03_최종성과품/033 설계서/내역서"] = new List<string> { "내역서", "공사비", "산출내역", "견적서", "단가표", "일위대가", "설계내역", "공사내역" }, ["03_최종성과품/034 시방서"] = new List<string> { "시방서", "특별시방서", "일반시방서", "표준시방서", "시공기준", "기술규격", "공사시방서" }, ["03_최종성과품/035 수량산출서"] = new List<string> { "수량산출", "물량산출", "자재산출", "수량집계", "공종별수량", "토공량", "콘크리트량" }, ["03_최종성과품/036 설계도면"] = new List<string> { "도면", "설계도", "CAD", "DWG", "DXF", "평면도", "단면도", "상세도", "배치도", "구조도" }, ["03_최종성과품/037 외주보고서/0381 기상자료"] = new List<string> { "기상", "기후", "날씨", "풍향", "풍속", "강우", "기상분석", "기후분석", "기상자료" }, ["03_최종성과품/037 외주보고서/0382 측량보고서"] = new List<string> { "측량", "지형", "현황측량", "GPS", "레벨", "측량보고", "지형측량", "수준측량" }, ["03_최종성과품/037 외주보고서/0383 수치보고서"] = new List<string> { "수치해석", "시뮬레이션", "모델링", "전산해석", "수치모델", "유한요소", "CFD" }, ["03_최종성과품/037 외주보고서/0384 해역이용협의서"] = new List<string> { "해역", "해양", "항만", "어업권", "해역이용", "해역협의", "공유수면", "해상공사" }, // 04_행정관련 - 프로젝트 수행 중 행정 문서 ["04_행정관련/041 외주관련"] = new List<string> { "하도급", "외주계약", "협력업체", "용역계약", "외주업체", "외주과업", "외주지시서", "외주기성" }, ["04_행정관련/042 기성관련"] = new List<string> { "기성", "기성검사", "기성청구", "대금지급", "선금", "기성신청", "기성검사원", "기성내역" }, ["04_행정관련/043 준공관련"] = new List<string> { "준공", "준공검사", "하자보수", "준공정산", "완료검사", "준공계", "준공검사원", "준공내역" }, ["04_행정관련/044 공문/0441 발송공문"] = new List<string> { "발송", "송부", "제출공문", "발신", "통보공문" }, ["04_행정관련/044 공문/0442 수신공문"] = new List<string> { "수신", "접수", "수령", "지시공문", "요청공문" }, ["04_행정관련/045 기타"] = new List<string> { "보험", "보증서", "인증서", "증명서", "확인서", "이행보증", "계약보증", "각서" } }; public static void Main(string[] args) { string sourceFolder = @"C:\프로젝트_원본폴더"; string targetFolder = @"C:\프로젝트명"; var organizer = new ProjectFileOrganizer(); var logger = new ClassificationLogger(); organizer.OrganizeProject(sourceFolder, targetFolder, logger); // 분류 로그 저장 logger.SaveToFile(Path.Combine(targetFolder, "분류결과.txt")); } public void OrganizeProject(string sourceFolder, string targetFolder, ClassificationLogger logger) { try { Console.WriteLine("1. 폴더 구조 생성 중..."); CreateFolderStructure(targetFolder); Console.WriteLine("2. 파일 분류 시작..."); ClassifyAndCopyFiles(sourceFolder, targetFolder, logger); // 분류 통계 출력 PrintStatistics(logger); Console.WriteLine("\n파일 분류가 완료되었습니다."); } catch (Exception ex) { Console.WriteLine($"오류 발생: {ex.Message}"); } } private void CreateFolderStructure(string targetFolder) { foreach (var folder in FolderStructure) { string fullPath = Path.Combine(targetFolder, folder.Key); Directory.CreateDirectory(fullPath); foreach (var subFolder in folder.Value) { string subPath = Path.Combine(fullPath, subFolder); Directory.CreateDirectory(subPath); } } } private void ClassifyAndCopyFiles(string sourceFolder, string targetFolder, ClassificationLogger logger) { var files = Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories); int totalFiles = files.Length; int processedFiles = 0; foreach (var file in files) { processedFiles++; string fileName = Path.GetFileName(file); string relativePath = Path.GetRelativePath(sourceFolder, file); // 도면 폴더 구조 유지 여부 확인 bool preserveStructure = ShouldPreserveStructure(file, relativePath); // 파일 분류 var classification = ClassifyFile(file, preserveStructure); string targetSubFolder = classification.Folder; // 대상 경로 결정 string destinationPath; if (preserveStructure && targetSubFolder == "03_최종성과품/036 설계도면") { // 도면의 경우 기존 폴더 구조 유지 string subPath = Path.GetDirectoryName(relativePath); destinationPath = Path.Combine(targetFolder, targetSubFolder, subPath, fileName); Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)); } else { destinationPath = Path.Combine(targetFolder, targetSubFolder, fileName); } // 중복 파일 처리 if (File.Exists(destinationPath)) { destinationPath = GetUniqueFilePath(destinationPath); } File.Copy(file, destinationPath, false); // 로그 기록 logger.AddLog(fileName, file, targetSubFolder, classification.Reason); // 진행상황 표시 Console.WriteLine($"[{processedFiles}/{totalFiles}] {fileName} -> {targetSubFolder}"); } } private bool ShouldPreserveStructure(string filePath, string relativePath) { string extension = Path.GetExtension(filePath).ToLower(); string[] drawingExtensions = { ".dwg", ".dxf", ".dwf", ".plt" }; // 도면 파일이고 하위 폴더에 있는 경우 return drawingExtensions.Contains(extension) && Path.GetDirectoryName(relativePath) != ""; } private (string Folder, string Reason) ClassifyFile(string filePath, bool preserveStructure) { string fileName = Path.GetFileName(filePath).ToLower(); string extension = Path.GetExtension(filePath).ToLower(); string fileContent = ""; // 텍스트 파일 내용 읽기 if (IsTextFile(extension)) { try { fileContent = File.ReadAllText(filePath, System.Text.Encoding.Default).ToLower(); } catch { } } // 우선순위별 분류 var priorityOrder = new[] { "00_계약관련", // 1순위: 계약 관련 "03_최종성과품", // 2순위: 최종 성과품 "01_보고관련", // 3순위: 공식 보고 "04_행정관련", // 4순위: 행정 문서 "02_회의 및 검토자료" // 5순위: 일반 회의 }; foreach (var priority in priorityOrder) { var matchingRules = ClassificationRules .Where(r => r.Key.StartsWith(priority)) .OrderByDescending(r => r.Key.Count(c => c == '/')) .ToList(); foreach (var rule in matchingRules) { var matchedKeywords = rule.Value .Where(keyword => fileName.Contains(keyword.ToLower()) || fileContent.Contains(keyword.ToLower())) .ToList(); if (matchedKeywords.Count >= 2 || (matchedKeywords.Count == 1 && fileName.Contains(matchedKeywords[0].ToLower()))) { return (rule.Key, $"키워드 매칭: {string.Join(", ", matchedKeywords)}"); } } } // 확장자 기반 분류 return ClassifyByExtension(fileName, extension); } private (string Folder, string Reason) ClassifyByExtension(string fileName, string extension) { switch (extension) { case ".dwg": case ".dxf": case ".dwf": case ".plt": return ("03_최종성과품/036 설계도면", "확장자: 도면 파일"); case ".xlsx": case ".xls": if (fileName.Contains("내역") || fileName.Contains("단가")) return ("03_최종성과품/033 설계서/내역서", "확장자+키워드: 엑셀 내역서"); if (fileName.Contains("수량") || fileName.Contains("산출")) return ("03_최종성과품/035 수량산출서", "확장자+키워드: 엑셀 수량산출"); break; case ".pptx": case ".ppt": if (fileName.Contains("보고회") || fileName.Contains("착수") || fileName.Contains("중간") || fileName.Contains("최종")) return ("01_보고관련", "확장자+키워드: 보고회 PPT"); return ("02_회의 및 검토자료", "확장자: 프레젠테이션"); } return ("05_미분류", "분류 규칙 없음"); } private bool IsTextFile(string extension) { var textExtensions = new[] { ".txt", ".doc", ".docx", ".pdf", ".hwp", ".rtf", ".html", ".htm" }; return textExtensions.Contains(extension.ToLower()); } private string GetUniqueFilePath(string filePath) { string directory = Path.GetDirectoryName(filePath); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath); string extension = Path.GetExtension(filePath); int counter = 1; string newFilePath; do { newFilePath = Path.Combine(directory, $"{fileNameWithoutExtension}_{counter}{extension}"); counter++; } while (File.Exists(newFilePath)); return newFilePath; } private void PrintStatistics(ClassificationLogger logger) { var statistics = logger.GetStatistics(); Console.WriteLine("\n=== 분류 통계 ==="); foreach (var stat in statistics.OrderByDescending(s => s.Value)) { Console.WriteLine($"{stat.Key}: {stat.Value}개"); } Console.WriteLine($"총 파일 수: {statistics.Sum(s => s.Value)}개"); } - Assistant
To address the requirement of updating the folder structure for
03_최종성과품and its associated classification rules, the following changes have been made to the code:1. Updated Folder Structure (
FolderStructureDictionary)The folder structure under
03_최종성과품has been reorganized to match the specified categories. Key changes include:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.