日期:2014-05-18 浏览次数:20965 次
DirectoryInfo di = new DirectoryInfo("路径"); DirectoryInfo[] dirs = di.GetDirectories(); for(int i=0;i<dirs.Lenght;i++) { comboBox.Items.Add(dirs[i].Name); }
------解决方案--------------------
楼上正解,这问题可简单啦!
------解决方案--------------------
string[] infos = Directory.GetDirectories("E:\\");
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("address"));
foreach (string info in infos)
{
string directoryName = info.Substring(info.LastIndexOf("\\")+1);
DataRow row=dt.NewRow();
row["address"] = directoryName;
dt.Rows.Add(row);
}
foreach (DataRow row in dt.Rows)
{
Console.WriteLine(row["address"].ToString());
}
------解决方案--------------------
路径没看到是绝对地址,我假定是C盘
记得加入IO using System.IO;
DirectoryInfo[] dirs = new DirectoryInfo("C:\\Program Files").GetDirectories();
for (int i = 0; i < dirs.Length; i++)
{
comboBox1.Items.Add(dirs[i].Name);
}
comboBox1.SelectedText = dirs[0].Name;
------解决方案--------------------
DirectoryInfo di = new DirectoryInfo("路径");
DirectoryInfo[] dirs = di.GetDirectories();
for(int i=0;i<dirs.Lenght;i++)
{
comboBox.Items.Add(dirs[i].Name);
}
------解决方案--------------------
DirectoryInfo di2 = new DirectoryInfo("filePath");
-----》
DirectoryInfo di2 = new DirectoryInfo(filePath);
filePath你传来的啊?
------解决方案--------------------
if (Directory.Exists(filePath)) { string[] directories = Directory.GetDirectories(filePath); foreach (string s in directories) { comboBox.Items.Add(s); } }