C#

디렉토리 안에 폴더 삭제 하기

탑~! 2016. 1. 7. 10:15

* 읽기 전용 파일 포함 디렉토리 삭제 방법 

using System.IO;
protected void DeleteTempDirectory()
{
    DirectoryInfo tempDirInfo = new DirectoryInfo("temp");

    if (tempDirInfo.Exists == true)
    {
        foreach (DirectoryInfo di in tempDirInfo.GetDirectories())
        {
            foreach (FileInfo fi in di.GetFiles())
            {
                if ( (fi.Attributes & FileAttributes.ReadOnly) > 0 )
                {
                    fi.Attributes = FileAttributes.Normal;
                }
            }
        }

        tempDirInfo.Delete(true);
    }
}


출처 : http://blog.daum.net/starkcb/117

728x90
반응형