当前位置: 编程技术>.net/c#/asp.net
c# 文件夹操作(创建或删除)的实现代码
来源: 互联网 发布时间:2014-08-30
本文导语: 完整代码如下: 代码示例: ///删除文件夹,参数文件夹路径 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(...
完整代码如下:
代码示例:
///删除文件夹,参数文件夹路径
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);
}
}
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);
}
}