C#노트(20) 새 폴더/폴더 삭제

2706 단어 c#
1. 새로 만들기
if (!Directory.Exists(""))
            {
                Directory.CreateDirectory("");
            }

2. 삭제
public static bool DelectDir(string strPath)
        {
            try
            {
                strPath = @strPath.Trim().ToString();//     
                if (System.IO.Directory.Exists(strPath))//          
                {
                    string[] strDirs = System.IO.Directory.GetDirectories(strPath);//        
                    string[] strFiles = System.IO.Directory.GetFiles(strPath);//       
                    foreach (string strFile in strFiles)//         
                    {
                        System.Diagnostics.Debug.Write(strFile + "-deleted");
                        System.IO.File.Delete(strFile);//      
                    }
                    foreach (string strdir in strDirs)//       
                    {
                        System.Diagnostics.Debug.Write(strdir + "-deleted");
                        System.IO.Directory.Delete(strdir, true);//     
                    }
                }
                return true;//   
            }
            catch (Exception Exp) //     
            {
                System.Diagnostics.Debug.Write(Exp.Message.ToString());//     
                return false;//   
            }
        }

좋은 웹페이지 즐겨찾기