//浏览文件夹
private void button1_Click(object sender, EventArgs e)
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
if (this.folderBrowserDialog1.SelectedPath.Trim() != "")
this.text_FolderName.Text = this.folderBrowserDialog1.SelectedPath.Trim();
}
}
//显示指定文件夹下的子文件夹
private void button2_Click(object sender, EventArgs e)
{
if (this.text_FolderName.Text.Trim() == "")
return;
this.listBox1.Items.Clear();
//获取指定文件夹下的所有子文件夹
string[] MyFolders = System.IO.Directory.GetDirectories(this.text_FolderName.Text);
this.listBox1.Items.AddRange(MyFolders);
}
private void button3_Click(object sender, EventArgs e)
{
//同时显示指定文件夹下的子文件夹和文件
if (this.text_FolderName.Text.Trim() == "")
return;
this.listBox1.Items.Clear();
//获取指定文件夹下的所有文件和子文件夹
string[] MyFoldersFiles = System.IO.Directory.GetFileSystemEntries(this.text_FolderName.Text);
this.listBox1.Items.AddRange(MyFoldersFiles);
}