Created
August 17, 2016 04:59
-
-
Save LGM-AdrianHum/201b3a8d772eb9cbf118883fd8fd2fd0 to your computer and use it in GitHub Desktop.
IterateFiles - Return a IEnumerable of strings.
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; | |
namespace SyncFTP | |
{ | |
public static class OsHelper | |
{/// <summary> | |
/// | |
/// </summary> | |
/// <param name="path"></param> | |
/// <param name="pattern"></param> | |
/// <returns></returns> | |
public static IEnumerable<string> IterateFiles(string path, string pattern) | |
{ | |
var entryQueue = new Queue<string>(); | |
entryQueue.Enqueue(path); | |
while (entryQueue.Count > 0) | |
{ | |
var subdirs = Directory.GetDirectories(entryQueue.Peek()); | |
var files = Directory.GetFiles(entryQueue.Peek(), pattern, SearchOption.TopDirectoryOnly); | |
foreach (var file in files) | |
yield return file; | |
entryQueue.Dequeue(); | |
foreach (var subdir in subdirs) | |
entryQueue.Enqueue(subdir); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment