본문 바로가기

전체 글

(44)
[C#] 폴더 (디렉토리) 삭제 class Lesson { public Lesson() { // 디렉토리 생성 CreateDir(@"C:\TestDir"); // 디렉토리 삭제 DeleteDir(@"C:\MainDir1\SubDir", true); } // 디렉토리 생성 private void CreateDir(string dirPath) { // 해당 경로에 존재하지 않는 디렉토리들 생성 System.IO.Directory.CreateDirectory(dirPath); } // 디렉토리 삭제 private void DeleteDir(string dirPath, bool recursive) { /* * recursive * true 인 경우 : 해당 디렉토리의 하위 디렉토리 및 파일 모두 삭제 * false 인 경우 : 해당 디렉토리만..
[C#] 파일 이동, 이름 변경 class Lesson { public Lesson() { // 디렉토리 생성 CreateDir(@"C:\TestDir"); // 파일 생성 CreateFile(@"C:\TestDir\File1.txt"); // 파일 이름 변경 ModifiedFileName(@"C:\TestDir\File1.txt", @"C:\TestDir\File10.txt"); // 디렉토리 생성 CreateDir(@"C:\MoveDir"); // 파일 이동 ModifiedFileName(@"C:\TestDir\File10.txt", @"C:\MoveDir\File10.txt"); } // 디렉토리 생성 private void CreateDir(string dirPath) { // 해당 경로에 존재하지 않는 디렉토리들 생성 Syst..
[C#] 폴더 (디렉토리) 이동, 이름 변경 class Lesson { public Lesson() { // 디렉토리 생성 CreateDir(@"C:\TestDir"); // 디렉토리 이름 변경 ModifiedDirName(@"C:\TestDir", @"C:\ModifiedDir"); // 디렉토리 생성 CreateDir(@"C:\MainDir"); // 디렉토리 이동 (ModifiedDir 폴더가 MainDir 폴더 내부로 이동) ModifiedDirName(@"C:\ModifiedDir", @"C:\MainDir\ModifiedDir"); } // 디렉토리 생성 private void CreateDir(string dirPath) { // 해당 경로에 존재하지 않는 디렉토리들 생성 System.IO.Directory.CreateDirectory..
[C#] 해당 폴더 (디렉토리) 의 내부 정보 가져오기 class Lesson { public Lesson() { // 해당 디렉토리 내부 정보 가져오기 string[] infos = GetDirInfos(@"C:\Windows"); foreach (string info in infos) { System.Console.WriteLine(info); } } // 해당 디렉토리의 하위 디렉토리, 파일 정보 가져오기 private string[] GetDirInfos(string dirPath) { System.IO.DirectoryInfo infos = new System.IO.DirectoryInfo(dirPath); System.Collections.Generic.List list = new System.Collections.Generic.List(); fo..
[C#] 파일 생성 class Lesson { public Lesson() { // 파일 생성 CreateFile(@"C:\MainDir\File1.txt"); CreateFile(@"C:\MainDir\File2.txt"); } // 파일 생성 private void CreateFile(string filePath) { // 해당 경로가 존재하지 않으면 예외 발생. System.IO.File.Create(filePath).Close(); } } 설명 생략 2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 생성 [C#] 폴더 (디렉토리) 생성 class Lesson { public Lesson() { // 메인디렉토리와 서브디렉토리 생성 CreateDir(@"C:\MainDir\SubDir"); } // 디렉토..
[C#] 폴더 (디렉토리) 존재 여부 확인 class Lesson { public Lesson() { // 디렉토리 존재 여부 확인 bool isExists = IsDirExists(@"C:\MainDir\SubDir"); System.Console.WriteLine(isExists); } // 디렉토리 존재 여부 확인 private bool IsDirExists(string dirPath) { // 존재시 true , 비존재시 false return System.IO.Directory.Exists(dirPath); } } 설명 생략 2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 생성 [C#] 폴더 (디렉토리) 생성 class Lesson { public Lesson() { // 메인디렉토리와 서브디렉토리 생성 CreateDir(..
[C#] 폴더 (디렉토리) 생성 class Lesson { public Lesson() { // 메인디렉토리와 서브디렉토리 생성 CreateDir(@"C:\MainDir\SubDir"); } // 디렉토리 생성 private void CreateDir(string dirPath) { // 해당 경로에 존재하지 않는 디렉토리들 생성 System.IO.Directory.CreateDirectory(dirPath); } } 너무나 간단하고 쉬워서 설명은 생략 2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 존재 여부 확인 [C#] 폴더 (디렉토리) 존재 여부 확인 class Lesson { public Lesson() { // 디렉토리 존재 여부 확인 bool isExists = IsDirExists(@"C:\MainDir\S..
[C#] 식 본문 메서드 ( =>) 전체 코드 namespace Test { class Program { static void Main(string[] args) { new Lesson(); } } class Lesson { public Lesson() { string name = GetName(); WriteName(name); int age = GetAge(); WriteAge(age); (string name1, int age1) = GetAllInfos(); WriteAllInfos(name1, age1); } // 식본문 메서드 형식들 // 반환형이 string 인 경우 본문에는 반환할 string 데이터가 있어야 함. public string GetName() => "C-Man"; // 반환형이 int 인 경우 본문에는 반환할 ..