How can i return List of directories instead of url's?

Posted by user1741587 on Stack Overflow See other posts from Stack Overflow or by user1741587
Published on 2012-10-24T22:56:18Z Indexed on 2012/10/24 23:00 UTC
Read the original article Hit count: 153

Filed under:

I have this function :

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;

        }

Its getting one url and return list of url's. Instead i want that the function will get a directory for example c:\ And it will return me a List of all directories in c:\ Not subsirectories just the directories in c:\ in my case it should be a List with a 14 directories.

Meaning in each index in the List a directory.

How can i do it ? Tried with Directory and DirectoryInfo but i just got messed up.

© Stack Overflow or respective owner

Related posts about c#