-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileDirMaker.cs
63 lines (55 loc) · 1.34 KB
/
FileDirMaker.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace RupPub
{
public class FileDirMaker
{
public FileDirMaker(DirectoryInfo baseDi, MatchRule[] allMatchRules)
{
BaseDirectoryInfo = baseDi;
AllRules = allMatchRules;
}
public DirectoryInfo BaseDirectoryInfo { get; set; }
public MatchRule[] AllRules { get; set; }
public FileInfo[] GetAllMatchFiles()
{
return getMatchFileInDirectory(BaseDirectoryInfo);
}
bool fileInfoMatchRules(FileInfo fi)
{
foreach (MatchRule rule in AllRules)
{
if (!rule.IsMatch(fi))
return false;
}
return true;
}
FileInfo[] getMatchFileInDirectory(DirectoryInfo di)
{
List<FileInfo> fileList = new List<FileInfo>();
foreach (FileInfo fi in di.GetFiles())
{
if (fileInfoMatchRules(fi))
fileList.Add(fi);
}
foreach (DirectoryInfo cdi in di.GetDirectories())
{
if ((cdi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden
&& Array.Exists<MatchRule>(AllRules, r => r.GetType() == typeof(SkipHideRule)))
{
continue;
}
if (AllRules.Where(r => r.ApplyForDirectory).Any(r => r.SkipDirectory(cdi)))
continue;
FileInfo[] cflist = getMatchFileInDirectory(cdi);
if (cflist.Length > 0)
{
fileList.AddRange(cflist);
}
}
return fileList.ToArray();
}
}
}