Skip to content

Instantly share code, notes, and snippets.

@taka-oyama
Last active October 5, 2016 01:37
Show Gist options
  • Save taka-oyama/a06f6ea413534007327d5b971cfa0d5d to your computer and use it in GitHub Desktop.
Save taka-oyama/a06f6ea413534007327d5b971cfa0d5d to your computer and use it in GitHub Desktop.
Get all files under a directory recursively
using System.Collections.Generic;
using System.IO;
public class Tester
{
static List<FileInfo> GetFilesRecursive(string path, string matchFormat = "*")
{
var files = new List<FileInfo>();
var lookups = new Stack<DirectoryInfo>(new [] { new DirectoryInfo(path) });
while(lookups.Count > 0) {
var lookup = lookups.Pop();
var dirs = lookup.GetDirectories();
foreach(var dir in dirs) {
lookups.Push(dir);
}
files.AddRange(lookup.GetFiles(matchFormat));
}
return files;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment