c# 文件(夹)创建与删除
程序员文章站
2023-11-25 13:50:10
复制代码 代码如下:/删除文件夹,参数文件夹路径 protected void deletedirectory(string dir,bool deletesubdir)...
复制代码 代码如下:
/删除文件夹,参数文件夹路径
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);
}
}
上一篇: iOS图片压缩、滤镜、剪切及渲染等详解