删除指定路径下的文件

string pathstr = System.Web.HttpContext.Current.Server.MapPath("/FilePath"); 
            if (Directory.Exists(pathstr))
            {
                //获取指定路径下所有文件夹
                //string[] folderPaths = Directory.GetDirectories(pathstr);

                //foreach (string folderPath in folderPaths)
                //    Directory.Delete(folderPath, true);
                //获取指定路径下所有文件
                string[] filePaths = Directory.GetFiles(pathstr);
                foreach (string itme in filePaths)
                {
                    System.IO.File.Delete(itme);
                }
            }

 

posted @ 2019-09-17 16:20  没有狐狸的南墙  阅读(361)  评论(0编辑  收藏  举报