Windows Phone Developers

Saturday, November 15, 2008

Get all Sub Directories under a folder using C# (.NET)

Get Sub Directories using C# (.NET)

Listing all subdirectories under a root directory using .NET (C#) is simple. You can use the DirectoryInfo..::.GetDirectories Method to list the directories

private static void ListDir(string rootdir)

{

try

{

DirectoryInfo[] DI = new DirectoryInfo(rootdir).GetDirectories("*.*", SearchOption.AllDirectories ) ;

foreach (DirectoryInfo D1 in DI)

{

Console.WriteLine(D1.FullName);

}

}

catch (DirectoryNotFoundException dEX)

{

Console.WriteLine("Directory Not Found " + dEX.Message);

}

catch (Exception ex)

{

Console.WriteLine(ex.Message);

}

}

Here is the overload list of GetDirectories method

Name

Description

GetDirectories()()()

Returns the subdirectories of the current directory.

GetDirectories(String)

Returns an array of directories in the current DirectoryInfo matching the given search criteria.

GetDirectories(String, SearchOption)

Returns an array of directories in the current DirectoryInfo matching the given search criteria and using a value to determine whether to search subdirectories.

C# GetDirectories()()() Method, C# GetSubDirectories Method, Dir Function in VB.NET, Dir Function in C#, List All Directories using C#, List Sub Directories using C#, How to get all subdirectories using C#

.NET GetDirectories()()() Method, .NET GetSubDirectories Method, Dir Function in VB.NET, Dir Function in .NET, List All Directories using .NET, List Sub Directories using .NET, How to get all subdirectories using .NET

See also :

VBA Dir Function to Get Sub Directories

C# Get All Files from a Folder

OpenFileDialog in Visual Basic .Net

Directory Size using VB.Net

Get Size of a Particular Directory using C# (.NET)

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment:

  1. Thank you very much.i got the solution for my question

    ReplyDelete

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005