62,025
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
public partial class Admin_ShanchuShuju : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FindFile("D:/beifen/");
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
public void FindFile(string dirPath) //参数dirPath为指定的目录
{
//在指定目录及子目录下查找文件,在listBox1中列出子目录及文件
DirectoryInfo Dir=new DirectoryInfo(dirPath);
try
{
foreach(DirectoryInfo d in Dir.GetDirectories())//查找子目录
{
FindFile(Dir+d.ToString()+"");
ListBox1.Items.Add(Dir+d.ToString()+""); //listBox1中填加目录名
}
foreach(FileInfo f in Dir.GetFiles("*.bak")) //查找文件
{
ListBox1.Items.Add(Dir+f.ToString()); //listBox1中填加文件名
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
//this.ListBox1.Items.RemoveAt(this.ListBox1.SelectedIndex);
string paths = this.ListBox1.SelectedItem.Value;
FileInfo file = new FileInfo(paths);
file.Delete();
Response.Redirect(Request.Url.ToString());
}
}