麦田

不积跬步无以至千里.

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
                var filePath = Server.MapPath(item.Path);
                if (File.Exists(filePath))
                {
                    //删除文件 同时判断文件下面是否还有文件 没有则将目录页删除了
                    File.Delete(filePath);
                    var directoryPath = Path.GetDirectoryName(item.Path);
                    DirectoryInfo di = new DirectoryInfo(directoryPath);
                    if (di.GetFiles().Length == 0)
                    {
                        di.Delete();
                    }
                }

 

//当前文件所在的目录没有文件的时候 删除当前目录
                        var directoryPath = Path.GetDirectoryName(p.Path);
                        DirectoryInfo di = new DirectoryInfo(directoryPath);
                        if (di.GetFiles().Length == 0)
                        {
                            di.Delete();
                        }

 

posted on 2016-09-06 09:55  一些记录  阅读(195)  评论(0)    收藏  举报