![](/img/trans.png)
[英]How can I load all dlls from a folder without knowing their names in c# .net?
[英]C# load folder names
我希望我的程序在解決方案中從文件夾中讀取子文件夾,但是我不知道如何讀取文件夾名稱。 我只能找到如何讀取文件名,這並不難工作,但是對於文件夾,這似乎並不是以相同的方式工作。
基本上,我想從“ Paevik”(2)子文件夾加載。
E:我忘了提,我想把那個清單放到我的comboBox中
有System.IO.Directory.EnumerateDirectories(string Path)
-方法。 它返回帶有目錄的集合。 例:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program
{
private static void Main(string[] args)
{
try
{
string dirPath = @"\\archives\2009\reports";
List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));
foreach (var dir in dirs)
{
Console.WriteLine("{0}", dir.Substring(dir.LastIndexOf("\\") + 1));
}
Console.WriteLine("{0} directories found.", dirs.Count);
}
catch (UnauthorizedAccessException UAEx)
{
Console.WriteLine(UAEx.Message);
}
catch (PathTooLongException PathEx)
{
Console.WriteLine(PathEx.Message);
}
}
}
參見MSDN 。
嘗試使用DirectoryInfo.EnumerateDirectories方法http://msdn.microsoft.com/zh-cn/library/dd413235.aspx
您可以使用“ GetDirectories”來檢索包含所有子目錄全名的數組。
string[] subdirectories = Directory.GetDirectories("Full path of your parent folder");
請參閱MSDN頁面上的示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.