The following is a fuzzy lookup of a file,
The specific function is: Select the folder, search all files hit the SHP layer with the word "_bui" (suffix. shp) and display the information in the ListView. The actual application can be modified casually.
The recursive method is used for deep search, and the shallow search is no longer recorded.
List<filedinfo>listed=new list<fileinfo> ();//storage of files that meet the requirements Filedinfo
String hz= "shp"//File suffix
private int k=0;
Public list<fileinfo>getallfiles (String path)
{
DirectoryInfo dir=new directorinfo (path);
if (!dir. Exists)//To determine whether a folder exists, generally directly select the folder is not a problem, here is the case of manual input
return null;
if (k<1)
{
Fileinfo[]fi=dir. GetFiles ();
for (int i=0;i<fi. length;i++)
{
String Filestr=fi[i]. Name;
if (filestr. Congtains (filestr. LastIndexOf (".") +1)) ==hz)
{
if (filestr. Contains ("_bui") | | Filestr. Contains ("_bui"))
List.add (Fi[i]);
}
}
k++;
}
Else
{
List<fileinfo>sublist=getfilesbydir (path);
foreach (FileInfo subfile in sublist)
{
List.add (Subfile);
}
}
directoryinfo[] SubDir = dir. GetDirectories ();
String spath = "";
foreach (DirectoryInfo d in SubDir)
{
spath = path + "\ \" + d.tostring () + "\ \";
Getallfiles (spath);
}
return List;
}
Private list<fileinfo> Getfilesbydir (string path)
{
DirectoryInfo di = new DirectoryInfo (path);
Locate the file in this directory
Fileinfo[] fi = di. GetFiles ();
Convert fileinfo[] Array to list
list<fileinfo> list = new list<fileinfo> ();
for (int i = 0; I < fi. Length; i++)
{
String filestr = Fi[i]. Name;
if (filestr. Substring (filestr. LastIndexOf (".") + 1)) = = Hz)
{
if (filestr. Contains ("_bui") | | Filestr. Contains ("_bui"))
List.add (Fi[i]);
}
}
return list;
}
C # searches for compliant files within a specified folder