Link to home
Start Free TrialLog in
Avatar of i_tiger
i_tiger

asked on

How to create file explorer using treeview control in c#?

I want to create file explorer just like the windows have. Do we require recursion for finding subfolders & files?
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Below are examples, in pseudo-code, to illustrate both concepts.

    -dZ.
// Recursively get all files
function RecursiveGetFile(string startPath, ArrayList list)
{
    foreach (string path in GetCurrDirFiles(startPath))
    {
        if ( IsDirectory(path) )
        {
            RecursiveGetFile(path, list);
        } else
        {
            list.Add(path);
        }
    }
}
 
// Get all files non-recursively
function GetFile(string startPath, ArrayList list)
{
    ArrayList dirList = new ArrayList();
    dirList.Add(startPath);
    int idx = 0;
 
    while (idx < dirList.Count)
    {
        foreach (string path in GetCurrDirFiles(dirList[idx]))
        {
            if ( IsDirectory(path) )
            {
                dirList.Add(path);
            }
            else
            {
                list.Add(path);
            }
        }
        idx++;
    }
}

Open in new window