No 51 · 删除文件夹中的所有文件

protected void Button2_Click(object sender, EventArgs e)
        {            
            System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(Server.MapPath("../Images/UploadFile/file/"));
            deletefile(path);

        }
        private void deletefile(System.IO.DirectoryInfo path)
        {
            foreach (System.IO.DirectoryInfo d in path.GetDirectories())
            {
                deletefile(d);
            }
            foreach (System.IO.FileInfo f in path.GetFiles())
            {
                f.Delete();
            }
        }

 

你可能感兴趣的:(No 51 · 删除文件夹中的所有文件)