2012-10-24 23 views
0

可能重複:
How can i get a string and return each time a string from array?如何返回目錄列表而不是網址?

我有這樣的功能:

private List<string> getLinks(HtmlAgilityPack.HtmlDocument document) 
     { 

      List<string> mainLinks = new List<string>(); 
      var linkNodes = document.DocumentNode.SelectNodes("//a[@href]"); 
      if (linkNodes != null) 
      { 
       foreach (HtmlNode link in linkNodes) 
       { 
        var href = link.Attributes["href"].Value; 
        if (href.StartsWith("http://") == true || href.StartsWith("https://") == true || href.StartsWith("www") == true) // filter for http 
        { 
         mainLinks.Add(href); 
        } 
       } 
      } 

      return mainLinks; 

     } 

它得到一個URL,返回的URL列表。 相反,我希望該函數將得到一個目錄例如c:\ 它會返回一個列表中的所有目錄在c:\ 不是子目錄只是c:\中的目錄,在我的情況下它應該是一個List一個14個目錄。

在列表中每個索引中的含義一個目錄。

我該怎麼辦?與目錄和DirectoryInfo嘗試,但我只是搞砸了。

+0

這與你的其他問題有何根本的不同? http://stackoverflow.com/questions/13058827/how-can-i-get-a-string-and-return-each-time-a-string-from-array – NotMe

回答

0

Directory.EnumerateDirectories(string path)返回靜態方法

An enumerable collection of the full names (including paths) for the directories in the directory specified by path. 

來源:MSDN

您可以使用類Path的方法來獲取一個目錄,例如名Path.GetDirectoryName(string path)。請仔細閱讀文檔MSDN

相關問題