[C#] 列示目錄下的檔案
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
List<string> FileItems = new List<string>();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{ ///folderBrowserDialog選取目錄
foreach (string File in Directory.GetFiles(folderBrowserDialog1.SelectedPath))
{
FileItems.Add(File); //
}
}
listBox1.DataSource = FileItems;
}
}
}
參考資料:
Getting a list of all the files in a directory
下一篇:[C#] 螢幕像素的座標與顏色