C#教程

关注公众号 jb51net

关闭
首页 > 软件编程 > C#教程 > c# 创建文件

c# 文件(夹)创建与删除

作者:

删除文件夹,参数文件夹路径
复制代码 代码如下:

/删除文件夹,参数文件夹路径
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);
}
}
您可能感兴趣的文章:
阅读全文