Jmouse.JFiles 类
来源:互联网 发布:淘宝直播账号怎么申请 编辑:程序博客网 时间:2024/06/06 19:52
Jmouse.JFiles
空间名称:Jmouse
类:JFiles
成员:JSearchOptions, JPatternOptions
方法:SetDirMethod, SetFileMethod, SetErrorMethod (+2 次重载), Search (+4 次重载)
此类是针对于 Directory 类的 GetFiles 和 GetDirectories 方法的一种完善。
当我们在使用 Directory 类的 GetFiles 和 GetDirectories 方法时,如果使用了 SearchOption.AllDirectories 来搜索子目录,则当 path 参数为卷时会出现“在 System.UnauthorizedAccessException 中第一次偶然出现的“mscorlib.dll”类型的异常”的 UnauthorizedAccessException 异常,这是因为当程序试图访问卷下的 System Volume Information 及其它无权访问的文件夹时发生了权限错误,而使用 Jmouse.JFiles 在对文件进行搜索时避开了该问题,并且程序员可以使用 SetErrorMethod 方法对异常进行自定义处理。
在 Jmouse.JFiles 中的成员:
JSearchOptions 设置搜索范围 JPatternOptions 当使用 searchPattern 查找特定文件时,决定 searchPattern 的适用范围
在 Jmouse.JFiles 中的方法: SetDirMethod 需要重写,此方法可以得到并处理所有文件夹的绝对路径 SetFileMethod 需要重写,此方法可以得到并处理所有文件的绝对路径 SetErrorMethod 需要重写,此方法可以得到并处理在搜索过程中发生的异常 (+2 次重载) Search 此方法用来搜索文件及文件夹,并返回出错文件及文件夹的个数 (+4 次重载)
*关于方法的参数和重写规则可以通过查看 Jmouse.JFiles 的源码来获取
*对于 Search 参数中的所有参数,除 JSearchOptions 和 JPatternOptions 外均与原 Directory 类中的 GetFiles 和 GetDirectories 方法的参数要求或格式相同。
示例(C#):
此文章适用于 Windows Vista, Windows XP, Windows 2000, Windows NT, Windows ME, Windows 98, Windows 95
空间名称:Jmouse
类:JFiles
成员:JSearchOptions, JPatternOptions
方法:SetDirMethod, SetFileMethod, SetErrorMethod (+2 次重载), Search (+4 次重载)
此类是针对于 Directory 类的 GetFiles 和 GetDirectories 方法的一种完善。
当我们在使用 Directory 类的 GetFiles 和 GetDirectories 方法时,如果使用了 SearchOption.AllDirectories 来搜索子目录,则当 path 参数为卷时会出现“在 System.UnauthorizedAccessException 中第一次偶然出现的“mscorlib.dll”类型的异常”的 UnauthorizedAccessException 异常,这是因为当程序试图访问卷下的 System Volume Information 及其它无权访问的文件夹时发生了权限错误,而使用 Jmouse.JFiles 在对文件进行搜索时避开了该问题,并且程序员可以使用 SetErrorMethod 方法对异常进行自定义处理。
在 Jmouse.JFiles 中的成员:
JSearchOptions 设置搜索范围 JPatternOptions 当使用 searchPattern 查找特定文件时,决定 searchPattern 的适用范围
在 Jmouse.JFiles 中的方法:
*关于方法的参数和重写规则可以通过查看 Jmouse.JFiles 的源码来获取
*对于 Search 参数中的所有参数,除 JSearchOptions 和 JPatternOptions 外均与原 Directory 类中的 GetFiles 和 GetDirectories 方法的参数要求或格式相同。
示例(C#):
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Jmouse; //引用 Jmouse 空间
namespace MyConsole
...{
class MyClass
...{
static void Main(string[] args)
...{
newJFiles clsJFiles = new newJFiles();
//搜索并显示所有文件及文件夹
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://").ToString());
//搜索并显示根目录下的所有文件及文件夹
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://",
JFiles.JSearchOptions.OnlyTopDirectory).ToString());
//搜索并显示所有以 "J" 开头的文件及文件夹
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://",
"J*",
JFiles.JPatternOptions.Both).ToString());
//搜索并显示所有根目录下以 "J" 开头的文件
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://",
"J*",
JFiles.JPatternOptions.OnlyFiles,
JFiles.JSearchOptions.OnlyTopDirectory).ToString());
//构建一个错误,".."是非法字符
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://",
"..",
JFiles.JPatternOptions.Both).ToString());
}
}
public class newJFiles : JFiles
...{
/**//*newJFiles 派生自 Jmouse.JFiles,并重写所有方法来列出搜索到的
文件、文件夹以及搜索中出现的错误*/
protected override void SetDirMethod(string[] path)
...{
if (path.Length > 0)
...{
for (int j = 0; j < path.Length; j++)
...{
Console.WriteLine(path[j]);
}
}
}
protected override void SetFileMethod(string[] path)
...{
if (path.Length > 0)
...{
for (int j = 0; j < path.Length; j++)
...{
Console.WriteLine(path[j]);
}
}
}
protected override void SetErrorMethod(string path,
Exception e)
...{
Console.WriteLine(" 错误:{0}", e.Message);
}
protected override void SetErrorMethod(string path,
string searchPattern, Exception e)
...{
Console.WriteLine(" 错误:{0}", e.Message);
Console.WriteLine("这可能是由于您使用的 {0} 字符中包含了非法字符。"
, searchPattern);
}
}
}
using System.Collections.Generic;
using System.Text;
using System.IO;
using Jmouse; //引用 Jmouse 空间
namespace MyConsole
...{
class MyClass
...{
static void Main(string[] args)
...{
newJFiles clsJFiles = new newJFiles();
//搜索并显示所有文件及文件夹
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://").ToString());
//搜索并显示根目录下的所有文件及文件夹
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://",
JFiles.JSearchOptions.OnlyTopDirectory).ToString());
//搜索并显示所有以 "J" 开头的文件及文件夹
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://",
"J*",
JFiles.JPatternOptions.Both).ToString());
//搜索并显示所有根目录下以 "J" 开头的文件
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://",
"J*",
JFiles.JPatternOptions.OnlyFiles,
JFiles.JSearchOptions.OnlyTopDirectory).ToString());
//构建一个错误,".."是非法字符
Console.WriteLine(" 搜索完毕,共有 {0} 个文件及文件夹在搜索中发生了错误。",
clsJFiles.Search("C://",
"..",
JFiles.JPatternOptions.Both).ToString());
}
}
public class newJFiles : JFiles
...{
/**//*newJFiles 派生自 Jmouse.JFiles,并重写所有方法来列出搜索到的
文件、文件夹以及搜索中出现的错误*/
protected override void SetDirMethod(string[] path)
...{
if (path.Length > 0)
...{
for (int j = 0; j < path.Length; j++)
...{
Console.WriteLine(path[j]);
}
}
}
protected override void SetFileMethod(string[] path)
...{
if (path.Length > 0)
...{
for (int j = 0; j < path.Length; j++)
...{
Console.WriteLine(path[j]);
}
}
}
protected override void SetErrorMethod(string path,
Exception e)
...{
Console.WriteLine(" 错误:{0}", e.Message);
}
protected override void SetErrorMethod(string path,
string searchPattern, Exception e)
...{
Console.WriteLine(" 错误:{0}", e.Message);
Console.WriteLine("这可能是由于您使用的 {0} 字符中包含了非法字符。"
, searchPattern);
}
}
}
此文章适用于 Windows Vista, Windows XP, Windows 2000, Windows NT, Windows ME, Windows 98, Windows 95
- Jmouse.JFiles 类
- Jmouse.JFiles 代码(C#)
- 帮助 - Jmouse PowerCalculator
- 试用 Jmouse PowerCalculator
- 紧急停用 Jmouse 1.8 Convert DLL v1.0.0.1
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- asp.net图片上传后,图片实际删除总结
- FreeBSD下查看文件夹大小的方法
- 关于spring事务的一组文章
- VS2005中类似删除确认总结
- 修改uxtheme.exe ,打造自己的主题
- Jmouse.JFiles 类
- VB中用正则表达式判断一个字符串是不是一个URL地址
- 英雄会,会英雄,CSDN大会有感
- 也许是商机
- Gridview中生成的属性rules="all",在Firefox出现内线框解决办法
- asp 内容按行数或字数分页
- 【原创】StrutsLogin静态验证....
- WJ的Direct3D简明教程1:Save Screen To the Image
- vb.net 通过类厂创建com对象的方法