当前位置: 编程技术>.net/c#/asp.net
c# 文件(夹)创建与删除
来源: 互联网 发布时间:2014-10-14
本文导语: 代码如下:/删除文件夹,参数文件夹路径 protected void DeleteDirectory(string dir,bool deleteSubDir) { try { Directory.Delete(dir, deleteSubDir); } catch (Exception e) { logger.Error("DeleteDirectory Error dir = " + dir, e); throw new Exception("DeleteDirectory Error dir = " + dir, ...
代码如下:
/删除文件夹,参数文件夹路径
protected void DeleteDirectory(string dir,bool deleteSubDir)
{
try
{
Directory.Delete(dir, deleteSubDir);
}
catch (Exception e)
{
logger.Error("DeleteDirectory Error dir = " + dir, e);
throw new Exception("DeleteDirectory Error dir = " + dir, e);
}
}
//删除路径,输入参数,文件路径
protected void DeleteFile(string dir)
{
try
{
File.Delete(dir);
}
catch (Exception e)
{
logger.Error("DeleteDirectory Error dir = " + dir, e);
throw new Exception("DeleteDirectory Error dir = " + dir, e);
}
}
//根据参数创建文件夹
protected void CreateDirectory(string dir)
{
try
{
if (Directory.Exists(dir))
{
logger.Warning("This Direcotry is exists dir = " + dir);
return;
}
Directory.CreateDirectory(dir);
}
catch (Exception e)
{
logger.Error("CreateDicectory Error dir = " + dir, e);
throw new ServerSystemException("CreateDicectory Error dir = " + dir, e);
}
}