首页导航栏 - 网络工程 | 网站建设 | 设计在线 | 精彩图片 | 职业前线 | 创业之路 | 启步工具 | 教程资讯 | 休闲娱乐
启步网 > 设计在线 > 程序设计
C#使用WIN32API来遍历文件和目录[3]
作者: 不详 阅读: 来源:互连网 时间:2007-1-4 13:16:14
字体

    #region 控制对象特性的一些属性 ****************************************
  
   private bool bolThrowIOException = true;
   /// <summary>
   /// 发生IO错误时是否抛出异常
   /// </summary>
   public bool ThrowIOException
   {
   get { return this.bolThrowIOException; }
   set { this.bolThrowIOException = value; }
   }
   private bool bolReturnStringType = true;
   /// <summary>
   /// 是否以字符串方式返回查询结果,若返回true则当前对象返回为字符串,
   /// 否则返回 System.IO.FileInfo或System.IO.DirectoryInfo类型
   /// </summary>
   public bool ReturnStringType
   {
   get { return bolReturnStringType; }
   set { bolReturnStringType = value; }
   }
  
   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; }
   }
  
   #endregion
  
   /// <summary>
   /// 关闭对象,停止搜索
   /// </summary>
   public void Close()
   {
   this.CloseHandler();
   }
  
   #region IEnumerator 成员 **********************************************
  
   /// <summary>
   /// 返回当前对象
   /// </summary>
   public object Current
   {
   get { return objCurrentObject ; }
   }
   /// <summary>
   /// 找到下一个文件或目录
   /// </summary>
   /// <returns>操作是否成功</returns>
   public bool MoveNext()
   {
   bool success = false;
   while (true)
   {
   if (this.bolStartSearchFlag)
   success = this.SearchNext();
   else
   success = this.StartSearch();
   if (success)
   {
   if (this.UpdateCurrentObject())
   return true;
   }
   else
   {
   this.objCurrentObject = null;
   return false;
   }
   }
   }
  
   /// <summary>
   /// 重新设置对象
   /// </summary>
   public void Reset()
   {
   if (this.strSearchPath == null)
   throw new System.ArgumentNullException("SearchPath can not null");
   if (this.strSearchPattern == null || this.strSearchPattern.Length == 0)
   this.strSearchPattern = "*";
  
   this.intSearchedCount = 0;
   this.objCurrentObject = null;
   this.CloseHandler();
   this.bolStartSearchFlag = false;
   this.bolIsEmpty = false;
   this.intLastErrorCode = 0;
   }
  
   #endregion

责任编辑:一路狂奔
帐号:
密码:

Google
Google提供的相关资源
参与评论(条评论)
请遵守国家法律
笔名:
邮箱:
( 以上评论仅代表网友个人意见,不代表本站观点 )
相关资源
  • C#使用WIN32API来遍历文件和目录[5] [2007-1-4]
  • C#使用WIN32API来遍历文件和目录[4] [2007-1-4]
  • C#使用WIN32API来遍历文件和目录[2] [2007-1-4]
  • C#使用WIN32API来遍历文件和目录[1] [2007-1-4]
  •