您的位置:首页>软件开发>C/C++>

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

[ 来源:AspCool | 更新日期:2007-7-15 20:20:11 | 评论 0 条 | 我要投稿 ]
#region 控制对象特性的一些属性 ****************************************

private bool bolThrowIOException = true;
///
/// 发生IO错误时是否抛出异常
///
public bool ThrowIOException
{
get { return this.bolThrowIOException; }
set { this.bolThrowIOException = value; }
}
private bool bolReturnStringType = true;
///
/// 是否以字符串方式返回查询结果,若返回true则当前对象返回为字符串,
/// 否则返回 System.IO.FileInfo或System.IO.DirectoryInfo类型
///
public bool ReturnStringType
{
get { return bolReturnStringType; }
set { bolReturnStringType = value; }
}

字串6



private string strSearchPattern = "*";
///
/// 要匹配的文件或目录名,支持通配符
///
public string SearchPattern
{
get { return strSearchPattern; }
set { strSearchPattern = value; }
}
private string strSearchPath = null;
///
/// 搜索的父目录,必须为绝对路径,不得有通配符,该目录必须存在
///
public string SearchPath
{
get { return strSearchPath; }
set { strSearchPath = value; }
}

private bool bolSearchForFile = true;
///
/// 是否查找文件
///
字串3

public bool SearchForFile
{
get { return bolSearchForFile; }
set { bolSearchForFile = value; }
}
private bool bolSearchForDirectory = true;
///
/// 是否查找子目录
///
public bool SearchForDirectory
{
get { return bolSearchForDirectory; }
set { bolSearchForDirectory = value; }
}

#endregion

///
/// 关闭对象,停止搜索
///
public void Close()
{
this.CloseHandler();
}

#region IEnumerator 成员 ********************************************** 字串9

///
/// 返回当前对象
///
public object Current
{
get { return objCurrentObject ; }
}
///
/// 找到下一个文件或目录
///
/// 操作是否成功
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
{

字串3


this.objCurrentObject = null;
return false;
}
}
}

///
/// 重新设置对象
///
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;
}
字串7

#endregion
Tags:
责任编辑:
您的评论
用户名: 新注册) 密码: 匿名评论 [所有评论]

·用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为