//获取文件夹的路径
private void button8_Click(object sender, EventArgs e)
{
this.comboBox1.Items.Clear();
ArrayList list = new ArrayList();
this.getChirDir(@"C:\bbb", ref list);
for (int i = 0; i < list.Count; i++)
{
comboBox1.Items.Add(list[i]);
}
}
private void getChirDir(string strRoot, ref ArrayList arrilist)
{
string[] dirr = Directory.GetDirectories(strRoot);
foreach (string dir in dirr)
{
arrilist.Add(dir);
getChirDir(dir, ref arrilist);
}
}
//获取文件的路径
private void button9_Click(object sender, EventArgs e)
{
this.comboBox1.Items.Clear();
//动态的方法
//DirectoryInfo obj = new DirectoryInfo(@"C:\bbb");
//FileInfo[] objfile = obj.GetFiles();
//foreach (FileInfo file in objfile)
//{
// this.comboBox1.Items.Add(file.FullName);
//}
//静态方法
string[] filepath=Directory.GetFiles(@"C:\bbb");
foreach (string filename in filepath)
{
this.comboBox1.Items.Add(filename);
}
}
转载于:https://www.cnblogs.com/yinyao/archive/2009/11/26/1611281.html