服務(wù)熱線
153 8323 9821
下面這個(gè)文件操作類,可以刪除目錄并且不為空的目錄哦,也可以創(chuàng)建文件寫(xiě)文件,刪除文件以前遞歸操作目錄。
using system.io;
using system.web;
namespace sec
{
/××////
/// 對(duì)文件和文件夾的操作類
///
public class filecontrol
{
public filecontrol()
{
}
/××////
/// 在根目錄下創(chuàng)建文件夾
///
/// 要?jiǎng)?chuàng)建的文件路徑
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;
}
}
}
/××////
/// 刪除一個(gè)文件夾下面的字文件夾和文件
///
///
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;
}
}
}
/××////
/// 刪除一個(gè)文件
///
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
{
//創(chuàng)建文件夾
string[] strpath= filepathname.split('/');
&nbs