Recursion
Using System;
Using System.IO;
Using System.Collections;
Namespace Dsclub
{
/**////<summary>
Summary description of the dirlist.
</summary>
public class Dirlist
{
private string Strinitfilepath;
private bool Bfatchall;
//constructor
public dirlist ()
{
Bfatchall = false;
Strinitfilepath = "c:\\";
}
public dirlist (String strFilePath)
{
bfatchall = false;
Strinitfilepath = strFilePath;
}
//whether to recursively file all files
public bool Recursionfiles
{
Get
{
return bfatchall;
}
Set
{
Bfatchall = value;
}
}
//Get file Functions
public ArrayList GetFiles ()
{
return GetFiles (Strinitfilepath, Bfatchall);
}
public static ArrayList GetFiles (String strpath, BOOL Resultsall)
{
ArrayList al = new ArrayList ();
//Determine if the path exists
if (! Directory.Exists (strpath))
{
Throw (new ApplicationException ("Access path" + strpath +) does not exist, or it is not a folder. "));
}
string[] Temp = Directory.GetFiles (strpath);
foreach (string afile in temp)
{
al. ADD (Afile);
}
If no files exist in this directory, the folder path is returned and identified with///
if (temp. Length = = 0)
{
Al. ADD ("///" + strpath);
}
if (Resultsall)
{
temp = directory.getdirectories (strpath);
foreach (string Adir in temp)
{
Al. AddRange (GetFiles (Adir, Resultsall));
}
}
Return al;
}
}
}
There should be a system file check, and users can not access the system folder judgment, but this project is not used, and do not want to use try block effect efficiency.
Or the thought of recursion!