[C#]007_My007App_顯示文件夾裏所有文件的名字

 

添加一個BUTTON, ComboBox, FolderBrowserDialg1.

 

Code:

private void btnShowFile_Click(object sender, EventArgs e)
{
    FolderBrowserDialog fbdSetFolder = new FolderBrowserDialog();
    if (fbdSetFolder.ShowDialog() == DialogResult.OK)
    {
        DirectoryInfo dirFileFolder = new DirectoryInfo(fbdSetFolder.SelectedPath);
        if (!dirFileFolder.Exists)
        {
            return;
        }
        FileInfo[] fi = dirFileFolder.GetFiles();
        foreach (FileInfo file in fi)
        {
            cmbShowFile.Items.Add(file);
        }
    }
}

 

運行結果如下:

007

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章