/// <summary> /// �����ļ� /// </summary> /// <param name="path">·��</param> /// <param name="searchPattern">�����ַ���</param> /// <param name="searchOption">����ѡ��</param> /// <returns>�ҵ����ļ���</returns> public string[] SearchFile(string path, string searchPattern, SearchOption searchOption, SearcherEventHandler processCallBack = null) { ArrayList arrayList = new ArrayList(); try { string[] fs = Directory.GetFiles(path, searchPattern); foreach (string file in fs) { if (processCallBack != null) processCallBack(file, Path.GetFileName(file), 1); arrayList.Add(file); } } catch { } if (searchOption == SearchOption.AllDirectories) { try { string[] ds = Directory.GetDirectories(path); foreach (string dpath in ds) { if (processCallBack != null) processCallBack(dpath, "", 2); InternalGetFiles(dpath, arrayList, processCallBack); } } catch { } } return (string[])arrayList.ToArray(typeof(string)); }
void InternalGetFiles(string path, ArrayList array, SearcherEventHandler processCallBack) { try { string[] fs = Directory.GetFiles(path); foreach (string file in fs) { if (processCallBack != null) { processCallBack(file, Path.GetFileName(file), 1); } array.Add(file); } } catch { } try { string[] ds = Directory.GetDirectories(path); foreach (string dpath in ds) { if (processCallBack != null) { processCallBack(dpath, "", 2); } InternalGetFiles(dpath, array, processCallBack); } } catch { } }
/// <summary> /// 获取制定目录下所有的文件名 /// </summary> /// <param name="path">指定的目录</param> /// <param name="processCallBack">进度委托</param> /// <returns></returns> public string[] GetFiles(string path, SearcherEventHandler processCallBack = null) { ArrayList arrayList = new ArrayList(); try { string[] fs = Directory.GetFiles(path); foreach (string file in fs) { if (processCallBack != null) { processCallBack(file, Path.GetFileName(file), 1); } arrayList.Add(file); } } catch { } try { string[] ds = Directory.GetDirectories(path); foreach (string dpath in ds) { if (processCallBack != null) { processCallBack(dpath, "", 2); } InternalGetFiles(dpath, arrayList, processCallBack); } } catch { } return((string[])arrayList.ToArray(typeof(string))); }
void InternalSearchFile(string path, ArrayList array, string searchPattern, SearcherEventHandler processCallBack) { try { string[] fs = Directory.GetFiles(path, searchPattern); foreach (string file in fs) { if (processCallBack != null) processCallBack(file, Path.GetFileName(file), 1); array.Add(file); } } catch { } try { string[] ds = Directory.GetDirectories(path); foreach (string dpath in ds) { if (processCallBack != null) processCallBack(dpath, "", 2); InternalGetFiles(dpath, array, processCallBack); } } catch { } }