次の方法で共有


Recursively listing the files

This function will help you to list all the files with the specified extension recursively i.e. it will also list the files within the child directory.

private

static void BuildList(string searchPath, bool recursive, string ext, ArrayList files)

{

DirectoryInfo parentDir = new DirectoryInfo(searchPath);

DirectoryInfo[] children = parentDir.GetDirectories();

if (recursive && children.Length > 1)

{

foreach (DirectoryInfo Child in children)

{

BuildList(Child.FullName, recursive,ext,files);

}

}

FileInfo[] fileList = parentDir.GetFiles(ext);

foreach (FileInfo file in fileList)

{

files.Add(file.FullName);

}

}

Comments

  • Anonymous
    September 10, 2007
    What's wrong with SearchOption.AllDirectories?

  • Anonymous
    September 24, 2007
    This would come handy in places where you dont have SearchOption.AllDirectories option while using GetFiles method specially in Compact Framework