1.文件夹操作

 // 当该日期文件夹不存在的情况
                    if (!Directory.Exists(sPath))
                    {
                        // 创建文件夹
                        Directory.CreateDirectory(sPath);
                    }

2. 文件操作

<pre name="code" class="csharp">// 当该文件存在的情况
                    if (System.IO.File.Exists(HostingEnvironment.MapPath("~/Upload/Logs/" + dt + "/" + file.FileName)))
                    {
                        // 删除文件
                        System.IO.File.Delete(HostingEnvironment.MapPath("~/Upload/Logs/" + dt + "/" + file.FileName));
                    // 保存文件
                    file.SaveAs(Server.MapPath(path));
                    }


 

3.删除操作

 //删除文件夹以及文件夹中的子目录,<pre name="code" class="csharp">  //若要移除 path 中的目录、子目录和文件,则为 true;否则为 false。
System.IO.Directory.Delete(dir, true);

 



本文转载:CSDN博客