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();
|
}
|
}
|