Last active
October 5, 2016 01:37
-
-
Save taka-oyama/a06f6ea413534007327d5b971cfa0d5d to your computer and use it in GitHub Desktop.
Get all files under a directory recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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