安全中国首页 > 编程中心 > VC/C++编程
 
安全中国网友投稿专用上传FTP空间:
Ftp服务器:download.anqn.com
Ftp端口:21
用户名:anqn
密 码:anqn.com
 

C#使用WIN32API来遍历文件和目录[3]

更新时间:2008-7-7 10:43:05
责任编辑:ShellExp
热 点:
  C#使用WIN32API来遍历文件和目录[3]
  #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

 
学习软件编程开发技术,推荐加入以下软件编程培训班:
易语言软件编程培训班(简单易学)  Delphi软件编程培训班  VC++软件编程培训班
VB软件编程培训班  JAVA高端编程就业研发班

学习网站开发制作技术,推荐加入以下网站开发培训班:
ASP.net网站开发项目实战班  ASP语言网站建设培训班

学习网络安全入侵防护技术,推荐加入以下技术培训班:
大型网络安全入侵防护班  网站脚本程序全方位安全检测班

学习网络管理、网吧运营维护技术(网管),推荐加入以下培训班:
大型网吧技术管理人才特训班  Linux网络嵌入架构工程师培训班

学习专项特殊技术,推荐加入以下专项技术培训班:
软件与游戏外挂脱壳破解班(逆向工程)  赚钱王道-网赚技能培训班  Flash动画设计师就业特训班

 
相关编程
一日一文章
 
一日一软件
一日一动画