A simple GetDirectories question

  • Thread starter Thread starter Ing. Rajesh Kumar
  • Start date Start date
I

Ing. Rajesh Kumar

Hi everybody
I am populating a dropdown list with directory names from a given directory. But how can i get the names for all the sub sub sub directories ?

What i want is :
Let's say i have a directory which contains DIR_A, DIR_A contains DIR_B, DIR_B contains DIR_C.
I want to populate dropdown list as :
<asp:ListItem Value="DIR_A" Text="DIR_A"/>
<asp:ListItem Value="DIR_A/DIR_B" Text="DIR_B"/>
<asp:ListItem Value="DIR_A/DIR_B/DIR_C" Text="DIR_C"/>

Following code does not give the result i want
Dim dirInfo as New DirectoryInfo(Server.MapPath(path))
ddl_1.DataSource = dirInfo.GetDirectories()

Thanks in advance
Raja
 
GetDirectories() is not recursive. You have to manually do it.

An example is here: http://www.aspheute.com/english/20000804.asp

Hi everybody
I am populating a dropdown list with directory names from a given directory.
But how can i get the names for all the sub sub sub directories ?

What i want is :
Let's say i have a directory which contains DIR_A, DIR_A contains DIR_B,
DIR_B contains DIR_C.
I want to populate dropdown list as :
<asp:ListItem Value="DIR_A" Text="DIR_A"/>
<asp:ListItem Value="DIR_A/DIR_B" Text="DIR_B"/>
<asp:ListItem Value="DIR_A/DIR_B/DIR_C" Text="DIR_C"/>

Following code does not give the result i want
Dim dirInfo as New DirectoryInfo(Server.MapPath(path))
ddl_1.DataSource = dirInfo.GetDirectories()

Thanks in advance
Raja
 
Hi,

This is a good recursive function that've used and is available in msdn.

void DirSearch(string sDir)
{
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d,
txtFile.Text))
{
lstFilesFound.Items.Add(f);
}
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}


HTH
Anoop
Hi everybody
I am populating a dropdown list with directory names from a given directory.
But how can i get the names for all the sub sub sub directories ?

What i want is :
Let's say i have a directory which contains DIR_A, DIR_A contains DIR_B,
DIR_B contains DIR_C.
I want to populate dropdown list as :
<asp:ListItem Value="DIR_A" Text="DIR_A"/>
<asp:ListItem Value="DIR_A/DIR_B" Text="DIR_B"/>
<asp:ListItem Value="DIR_A/DIR_B/DIR_C" Text="DIR_C"/>

Following code does not give the result i want
Dim dirInfo as New DirectoryInfo(Server.MapPath(path))
ddl_1.DataSource = dirInfo.GetDirectories()

Thanks in advance
Raja
 
Back
Top