[C#/COMMON] DirectoryInfo 클래스 : Delete 메소드를 사용해 하위 디렉토리 및 파일 포함 디렉토리 삭제하기
C#/Common 2020. 10. 24. 22:21728x90
반응형
728x170
▶ DirectoryInfo 클래스 : Delete 메소드를 사용해 하위 디렉토리 및 파일 포함 디렉토리 삭제하기 예제
using System;
bool result = DeleteDirectory("d:\\test1");
Console.WriteLine(result);
728x90
▶ DirectoryInfo 클래스 : Delete 메소드를 사용해 하위 디렉토리 및 파일 포함 디렉토리 삭제하기
using System;
using System.IO;
#region 디렉토리 삭제하기 - DeleteDirectory(targetDirectoryPath)
/// <summary>
/// 디렉토리 삭제하기
/// </summary>
/// <param name="targetDirectoryPath">타겟 디렉토리 경로</param>
/// <returns>처리 결과</returns>
/// <remarks>하위 디렉토리 및 파일 모두 삭제한다.</remarks>
public bool DeleteDirectory(string targetDirectoryPath)
{
try
{
DirectoryInfo directoryInfo = new DirectoryInfo(targetDirectoryPath);
directoryInfo.Delete(true);
return true;
}
catch(Exception)
{
return false;
}
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 누겟 설치 : MySql.Data (0) | 2020.11.03 |
---|---|
[C#/COMMON] 누겟 설치 : Npgsql (0) | 2020.11.03 |
[C#/COMMON] BASE64 URL 인코딩/디코딩하기 (0) | 2020.11.03 |
[C#/COMMON] 누겟 설치 : Microsoft.Extensions.Hosting (0) | 2020.10.27 |
[C#/COMMON] ILogger 인터페이스 : 콘솔에서 로그 생성하기 (0) | 2020.10.27 |
[C#/COMMON] DirectoryInfo 클래스 : Delete 메소드를 사용해 하위 디렉토리 및 파일 포함 디렉토리 삭제하기 (0) | 2020.10.24 |
[C#/COMMON] DirectoryInfo 클래스 : Create 메소드를 사용해 하위 디렉토리 일괄 생성하기 (0) | 2020.10.24 |
[C#/COMMON] SmtpClient 클래스 : Send 메소드를 사용해 메일 보내기 (0) | 2020.10.23 |
[C#/COMMON] 누겟 설치 : MailKit (0) | 2020.10.23 |
[C#/COMMON] IDisposable 인터페이스 사용하기 (0) | 2020.10.21 |
[C#/COMMON] PasswordHasher<T> 클래스 : HashPassword 메소드를 사용해 패스워드 해시값 구하기 (0) | 2020.10.20 |
댓글을 달아 주세요