c# 文件(夹)创建与删除
时间:2021-03-18 09:46:47|栏目:.NET代码|点击: 次
复制代码 代码如下:
/删除文件夹,参数文件夹路径
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);
}
}
栏 目:.NET代码
下一篇:C# 中的IComparable和IComparer的使用及区别
本文标题:c# 文件(夹)创建与删除
本文地址:http://www.codeinn.net/misctech/83334.html