Friday, November 28, 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

No comments: