首先要完成一个遍历所有文件的工作。
代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
namespace LauncherDataMaker
{
public partial class Form1 : Form
{
ArrayList FileList = new ArrayList();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo theFolder = new DirectoryInfo("c:\\software\\");
ArrayList Flst = GetAll(theFolder);
foreach(string strData in Flst)
{
this.listBox1.Items.Add(strData);
}
}
ArrayList GetAll(DirectoryInfo dir)//搜索文件夹中的文件
{
FileInfo[] allFile = dir.GetFiles();
foreach (FileInfo fi in allFile)
{
FileList.Add(fi.FullName);
}
DirectoryInfo[] allDir = dir.GetDirectories();
foreach (DirectoryInfo d in allDir)
{
GetAll(d);
}
return FileList;
}
}
}