List<string> SerchName = new List<string>(); //要查找的字段
public List<string> SerchName1
{
get { return SerchName; }
set { SerchName = value; }
}
//设置查找文件类型
private int i;
public int I
{
get { return i; }
set { i = value; }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Serch_File
{
class FindFile
{
public List<string> lst1 = new List<string>();
public List<string> getFile(string path, string extName, int i)//创建一个List<FileInfo>类型的函数
{
getdir(path, extName, i);//传入路径、搜索的字段 、将要搜索的类型
return lst1;
}
private void getdir(string path, string extName, int i)
{
try
{
//获取文件夹列表
string[] dirs = Directory.GetDirectories(path); DirectoryInfo fdir = new DirectoryInfo(path);
FileInfo[] file = fdir.GetFiles();
//当前目录文件或目录不为空
if (file.Length != 0 || dirs.Length != 0)
{
foreach (FileInfo f in file)
{
switch (i)
{
case 0: if (extName == f.Name) //根据文件名匹配上
{
lst1.Add(f.Name);
} break;
case 1: if (extName == f.Extension) //根据后缀名匹配上
{
lst1.Add(f.FullName);
} break;
}
}
foreach (string d in dirs)
{
getdir(d, extName, i);//递归
}
}
}
catch
{
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有