Code to list the list of directories of a particular path

Karthikanbarasan
Posted by Karthikanbarasan under C# category on | Points: 40 | Views : 1304
Call this ShowDirectory and loop through to get the list
as

intcount = ShowDirectory(DirInfo, 0, arraylist);
for (i = 0; i < arraylist.Count; i++)
{
lstdir.Items.Add(arraylist[i]);
}

const string strTABtocheck = " ";
static private int intvisit;
private int intdirCoun;

public int ShowDirectory(DirectoryInfo objcurDir, int intLevelfnd, ArrayList arraydirs)
{
int iinti;
string strindent = "";

try
{
for (iinti = 0; iinti < intvisit; iinti++)
{
strindent += strTABtocheck;
}

arraydirs.Add(strindent + objcurDir.Name);
intvisit++;

foreach (DirectoryInfo subDir in objcurDir.GetDirectories())
{
intdirCoun++;
ShowDirectory(subDir, intvisit, arraydirs);
}
intvisit--;

if (strindent.Length > 0)
strindent.Substring(0, strindent.Length - strTABtocheck.Length);
}
catch (Exception ex)
{
return -1;
}
return intdirCoun;
}

Comments or Responses

Login to post response