日期:2014-05-18 浏览次数:21100 次
private static string result = ""; /// <summary> /// 得某文件夹下所有的文件 /// </summary> /// <param name="directory">文件夹名称</param> /// <param name="pattern">搜寻指类型</param> /// <returns></returns> public static string GetFiles(DirectoryInfo directory, string pattern) { if(directory.Exists || pattern.Trim()!=string.Empty) { foreach(FileInfo info in directory.GetFiles(pattern)) { result = result + info.FullName.ToString() + ";"; //result = result + info.Name.ToString() + ";"; } foreach(DirectoryInfo info in directory.GetDirectories()) { GetFiles(info,pattern); } } string returnString = result; return returnString; } //调用 string file = bsGetFiles.GetFiles(new DirectoryInfo(@"D:\TestGetFiles"),"*.dll"); this.textBox1.Text = file;
------解决方案--------------------
要确定是否有权限。查找的结果是相对路径还是绝对路径?不论返回哪一个,都是很简单的遍历根目录,递归遍历子目录。
------解决方案--------------------
递归查询!
------解决方案--------------------