schangxiang@126.com
2024-09-03 953bc88c74023afffc12505635a22e84d9964c9c
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace iWare_SCADA_BusinessLogical.Utils
{
    /// <summary>
    /// FindFiles 实时查找文件
    /// </summary>
    /// <remarks>
    /// FindFiles e = new FindFiles();
    /// e.SearchPath = @"c:\";
    /// e.ReturnStringType = true ;
    /// e.SearchPattern = "*.exe";
    /// e.SearchForDirectory = false ;
    /// e.SearchForFile = true;
    /// e.SearchCreationTime = DateTime.Now.AddDays(-1);
    /// foreach (object name in e)
    /// {
    /// System.Console.WriteLine(name);
    /// }
    /// System.Console.ReadLine();
    /// 
    ///</remarks>
    public class FindFiles : System.Collections.IEnumerable
    {
        private bool bolReturnStringType = true;
        /// <summary>
        /// 如果为True返回文件名,否则返回 System.IO.FileInfo 或 System.IO.DirectoryInfo
        /// </summary>
        public bool ReturnStringType
        {
            get { return bolReturnStringType; }
            set { bolReturnStringType = value; }
        }
        /// <summary>
        /// 查询文件创建开始时间
        /// </summary>
        public DateTime? SearchCreationTime { get; set; }
        /// <summary>
        /// 查询文件创建结束时间
        /// </summary>
        public DateTime? SearchCreationEndTime { get; set; }
 
        /// <summary>
        /// 查询文件修改开始时间
        /// </summary>
        public DateTime? SearchModifyTime { get; set; }
        /// <summary>
        /// 查询文件修改结束时间
        /// </summary>
        public DateTime? SearchModifyEndTime { get; set; }
 
        private string strSearchPattern = "*";
        /// <summary>
        /// 查询条件
        /// </summary>
        public string SearchPattern
        {
            get { return strSearchPattern; }
            set { strSearchPattern = value; }
        }
        private string strSearchPath = null;
        /// <summary>
        /// 查询路径
        /// </summary>
        public string SearchPath
        {
            get { return strSearchPath; }
            set { strSearchPath = value; }
        }
        private bool bolSearchForFile = true;
        /// <summary>
        /// 查询文件
        /// </summary>
        public bool SearchForFile
        {
            get { return bolSearchForFile; }
            set { bolSearchForFile = value; }
        }
        private bool bolSearchForDirectory = true;
        /// <summary>
        /// 查询文件夹
        /// </summary>
        public bool SearchForDirectory
        {
            get { return bolSearchForDirectory; }
            set { bolSearchForDirectory = value; }
        }
        private bool bolThrowIOException = true;
        /// <summary>
        /// 是否抛出异常
        /// </summary>
        public bool ThrowIOException
        {
            get { return this.bolThrowIOException; }
            set { this.bolThrowIOException = value; }
        }
        /// <summary>
        /// IEnumerator接口
        /// </summary>
        /// <returns></returns>
        public System.Collections.IEnumerator GetEnumerator()
        {
            FileDirectoryEnumerator e = new FileDirectoryEnumerator();
            e.ReturnStringType = this.bolReturnStringType;
            e.SearchForDirectory = this.bolSearchForDirectory;
            e.SearchForFile = this.bolSearchForFile;
            e.SearchPath = this.strSearchPath;
            e.SearchPattern = this.strSearchPattern;
            e.ThrowIOException = this.bolThrowIOException;
            e.SearchCreationTime = this.SearchCreationTime;
            e.SearchCreationEndTime = this.SearchCreationEndTime;
            e.SearchModifyTime = this.SearchModifyTime;
            e.SearchModifyEndTime = this.SearchModifyEndTime;
            myList.Add(e);
            return e;
        }
        /// <summary>
        /// 关闭对象
        /// </summary>
        public void Close()
        {
            foreach (FileDirectoryEnumerator e in myList)
            {
                e.Close();
            }
            myList.Clear();
        }
        private System.Collections.ArrayList myList = new System.Collections.ArrayList();
    }
}