private void search()
{
// 多种后缀可使用 exts 定义的方式
var ext = "*.jpg";
var exts = "*.jpg *.png *.gif";
var folder = "D:\\";
var output = new StringBuilder();
if (System.IO.Directory.Exists(folder))
{
string path = System.IO.Path.Combine(folder, exts);
string args = string.Format("/c dir \"{0}\" /b/l/s", path);
// 如果仅搜索文件夹可以使用下面的参数组合
// string args = string.Format("/c dir \"{0}\" /ad-s-h/b/l/s", folder);
var compiler = new System.Diagnostics.Process();
compiler.StartInfo.FileName = "cmd.exe";
compiler.StartInfo.Arguments = args;
compiler.StartInfo.CreateNoWindow = true;
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.OutputDataReceived += (obj, p) =>
{
// 根据 p.Data 是否为空判断 dir 命令是否已执行完毕
if (string.IsNullOrEmpty(p.Data) == false)
{
output.AppendLine(p.Data);
// 可以写个自定义类 <T>
// 然后利用 static <T> FromFile(string path) 的方式进行实例化
// 最后利用 List<T>.Add 的方法将其加入到 List 中以便后续处理
// * 数据量很大时慎用
}
else
{
// 运行到此处则表示 dir 已执行完毕
// 可以在此处添加对 output 的处理过程
// 也可以自定义完成事件并在此处触发该事件,
// 将 output 作为事件参数进行传递以便外部程序调用
}
};
compiler.Start();
compiler.BeginOutputReadLine(); // 开始异步读取
compiler.Close();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有