首页导航栏 - 网络工程 | 网站建设 | 设计在线 | 精彩图片 | 职业前线 | 创业之路 | 启步工具 | 教程资讯 | 休闲娱乐
启步网 > 设计在线 > 程序设计
C#使用WIN32API来遍历文件和目录[5]
作者: 不详 阅读: 来源:互连网 时间:2007-1-4 13:17:30
字体
    /// <summary>
   /// 搜索下一个
   /// </summary>
   /// <returns>操作是否成功</returns>
   private bool SearchNext()
   {
   if (bolStartSearchFlag == false)
   return false;
   if (bolIsEmpty)
   return false;
   if (intSearchHandler == INVALID_HANDLE_VALUE)
   return false;
   intLastErrorCode = 0 ;
   if (FindNextFile(intSearchHandler, ref myData) == false)
   {
   intLastErrorCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
   this.CloseHandler();
   if (intLastErrorCode != 0 && intLastErrorCode != 0x12)
   {
   if (this.bolThrowIOException)
   WinIOError(intLastErrorCode , strSearchPath);
   else
   return false;
   }
   return false;
   }
   return true;
   }//private bool SearchNext()
  
   /// <summary>
   /// 更新当前对象
   /// </summary>
   /// <returns>操作是否成功</returns>
   private bool UpdateCurrentObject()
   {
   if (intSearchHandler == INVALID_HANDLE_VALUE)
   return false;
   bool Result = false;
   this.objCurrentObject = null;
   if ((myData.dwFileAttributes & 0x10) == 0)
   {
   // 当前对象为文件
   this.bolIsFile = true;
   if (this.bolSearchForFile)
   Result = true;
   }
   else
   {
   // 当前对象为目录
   this.bolIsFile = false;
   if (this.bolSearchForDirectory)
   {
   if (myData.cFileName == "." || myData.cFileName == "..")
   Result = false;
   else
   Result = true;
   }
   }
   if (Result)
   {
   if (this.bolReturnStringType)
   this.objCurrentObject = myData.cFileName;
   else
   {
   string p = System.IO.Path.Combine(this.strSearchPath, myData.cFileName);
   if (this.bolIsFile)
   {
   this.objCurrentObject = new System.IO.FileInfo(p);
   }
   else
   {
   this.objCurrentObject = new System.IO.DirectoryInfo(p);
   }
   }
   this.intSearchedCount++;
   }
   return Result;
   }//private bool UpdateCurrentObject()
  
   #endregion
  
  }//public class FileDirectoryEnumerator : System.Collections.IEnumerator

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

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