下面这个文件操作类,可以删除目录并且不为空的目录哦,也可以创建文件写文件,删除文件以前递归操作目录。
using system.io;
using system.web;
namespace sec
{
/××////
/// 对文件和文件夹的操作类
///
public class filecontrol
{
public filecontrol()
{
}
/××////
/// 在根目录下创建文件夹
///
/// 要创建的文件路径
public void createfolder(string folderpathname)
{
if(folderpathname.trim().length> 0)
{
try
{
string createpath = system.web.httpcontext.current.server.mappath("http://www.cnblogs.com/images/%22+folderpathname).tostring();
if(!directory.exists(createpath))
{
directory.createdirectory(createpath);
}
}
catch
{
throw;
}
}
}
/××////
/// 删除一个文件夹下面的字文件夹和文件
///
///
public void deletechildfolder(string folderpathname)
{
if(folderpathname.trim().length> 0)
{
try
{
string createpath = system.web.httpcontext.current.server.mappath(folderpathname).tostring();
if(directory.exists(createpath))
{
directory.delete(createpath,true);
}
}
catch
{
throw;
}
}
}
/××////
/// 删除一个文件
///
public void deletefile(string filepathname)
{
try
{
fileinfo delefile = new fileinfo(system.web.httpcontext.current.server.mappath(filepathname).tostring());
delefile.delete();
}
catch
{
}
}
public void createfile(string filepathname)
{
try
{
//创建文件夹
string[] strpath= filepathname.split('/');
&nbs
版权所有 2021-2024 石家庄建站平台 冀ICP备2022000585号-2 24小时服务热线:15383239821