본문 바로가기

C#

[C#] 파일 삭제

	class Lesson
	{
		public Lesson()
		{
			// 디렉토리 생성
			CreateDir(@"C:\TestDir");

			// 파일 생성
			CreateFile(@"C:\TestDir\File.txt");

			// 파일 삭제
			DeleteFile(@"C:\TestDir\File.txt");
		}

		// 디렉토리 생성
		private void CreateDir(string dirPath)
		{
			//  해당 경로에 존재하지 않는 디렉토리들 생성
			System.IO.Directory.CreateDirectory(dirPath);
		}

		// 파일 생성
		private void CreateFile(string filePath)
		{
			System.IO.File.Create(filePath).Close();
		}

		//  파일 삭제
		private void DeleteFile(string filePath)
		{
			System.IO.File.Delete(filePath);
		}
	}
  • 기능이 직관적이고 쉬워서 설명 생략

 

2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 삭제

 

[C#] 디렉토리 삭제

class Lesson { public Lesson() { // 디렉토리 생성 CreateDir(@"C:\TestDir"); // 디렉토리 삭제 DeleteDir(@"C:\MainDir1\SubDir", true); } // 디렉토리 생성 private void CreateDir(string dirPath) { // 해당 경로에 존재하지 않는 디

bysik1109.tistory.com

 

2023.10.07 - [C#] - [C#] 파일 이동, 이름 변경

 

[C#] 파일 이동, 이름 변경

class Lesson { public Lesson() { // 디렉토리 생성 CreateDir(@"C:\TestDir"); // 파일 생성 CreateFile(@"C:\TestDir\File1.txt"); // 파일 이름 변경 ModifiedFileName(@"C:\TestDir\File1.txt", @"C:\TestDir\File10.txt"); // 디렉토리 생성 Crea

bysik1109.tistory.com

 

2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 이동, 이름 변경

 

[C#] 폴더 (디렉토리) 이동, 이름 변경

class Lesson { public Lesson() { // 디렉토리 생성 CreateDir(@"C:\TestDir"); // 디렉토리 이름 변경 ModifiedDirName(@"C:\TestDir", @"C:\ModifiedDir"); // 디렉토리 생성 CreateDir(@"C:\MainDir"); // 디렉토리 이동 (ModifiedDir 폴더

bysik1109.tistory.com

 

2023.10.07 - [C#] - [C#] 해당 폴더 (디렉토리) 의 내부 정보 가져오기

 

[C#] 해당 폴더 (디렉토리) 의 내부 정보 가져오기

class Lesson { public Lesson() { // 해당 디렉토리 내부 정보 가져오기 string[] infos = GetDirInfos(@"C:\Windows"); foreach (string info in infos) { System.Console.WriteLine(info); } } // 해당 디렉토리의 하위 디렉토리, 파일 정

bysik1109.tistory.com

 

2023.10.07 - [C#] - [C#] 파일 생성

 

[C#] 파일 생성

class Lesson { public Lesson() { // 파일 생성 CreateFile(@"C:\MainDir\File1.txt"); CreateFile(@"C:\MainDir\File2.txt"); } // 파일 생성 private void CreateFile(string filePath) { // 해당 경로가 존재하지 않으면 예외 발생. System.IO.Fi

bysik1109.tistory.com

 

2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 존재 여부 확인

 

[C#] 폴더 (디렉토리) 존재 여부 확인

class Lesson { public Lesson() { // 디렉토리 존재 여부 확인 bool isExists = IsDirExists(@"C:\MainDir\SubDir"); System.Console.WriteLine(isExists); } // 디렉토리 존재 여부 확인 private bool IsDirExists(string dirPath) { // 존재시 true

bysik1109.tistory.com

 

2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 생성

'C#' 카테고리의 다른 글

[C#] out 매개변수  (2) 2023.10.10
[C#] 참조 매개변수 ref  (0) 2023.10.10
[C#] 폴더 (디렉토리) 삭제  (0) 2023.10.07
[C#] 파일 이동, 이름 변경  (0) 2023.10.07
[C#] 폴더 (디렉토리) 이동, 이름 변경  (0) 2023.10.07