forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryInfoExtensions.cs
More file actions
44 lines (38 loc) · 1.37 KB
/
DirectoryInfoExtensions.cs
File metadata and controls
44 lines (38 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#if !SILVERLIGHT
using System.Collections.Generic;
using System.IO;
namespace ServiceStack.Common
{
public static class DirectoryInfoExtensions
{
public static IEnumerable<string> GetMatchingFiles(this DirectoryInfo rootDirPath, string fileSearchPattern)
{
return GetMatchingFiles(rootDirPath.FullName, fileSearchPattern);
}
public static IEnumerable<string> GetMatchingFiles(string rootDirPath, string fileSearchPattern)
{
var pending = new Queue<string>();
pending.Enqueue(rootDirPath);
string[] paths;
while (pending.Count > 0)
{
rootDirPath = pending.Dequeue();
paths = Directory.GetFiles(rootDirPath, fileSearchPattern);
foreach (var filePath in paths) {
yield return filePath;
}
paths = Directory.GetDirectories(rootDirPath);
foreach (var dirPath in paths)
{
var dirAttrs = File.GetAttributes(dirPath);
var isRecurseSymLink = (dirAttrs & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint;
if (!isRecurseSymLink)
{
pending.Enqueue(dirPath);
}
}
}
}
}
}
#endif