f盘下有文件夹a,a文件夹下面有2012-2-2-22-22文件夹,2012-2-2-22-22文件夹下面有3.affix1和3.his1
protected void button1_Click(object sender, EventArgs e)
{
string name="";
DirectoryInfo theFolder = new DirectoryInfo(@"F:\a\");
DirectoryInfo[] dirInfo = theFolder.GetDirectories();
//遍历文件夹
foreach (DirectoryInfo NextFolder in dirInfo)
{
//遍历文件夹
//this.listBox2.Items.Add(NextFolder.Name);
// 遍历文件夹下文件
FileInfo[] fileInfo = NextFolder.GetFiles();
foreach (FileInfo NextFile in fileInfo) //遍历文件
{
name = NextFile.Name.ToString();
int i = name.LastIndexOf(".");
string ext = name.Substring(i);
string[] allowext = { ".his1", ".affix1" };
for (int a = 0; a < allowext.Length; a++)
{
if (ext == allowext[a])
{
// this.listBox2.Items.Add(NextFile.Name);
this.listBox2.Items.Add(name);
}
}
}
}
}