public class DirectoryAllFiles
{
static List<FileInformation> FileList = new List<FileInformation>();
public static List<FileInformation> GetAllFiles(DirectoryInfo dir)
{
FileInfo[] allFile = dir.GetFiles();
foreach (FileInfo fi in allFile)
{
FileList.Add(new FileInformation { FileName = fi.Name, FilePath = fi.FullName });
}
DirectoryInfo[] allDir = dir.GetDirectories();
foreach (DirectoryInfo d in allDir)
{
GetAllFiles(d);
}
return FileList;
}
}
public class FileInformation
{
public string FileName { get; set; }
public string FilePath { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
//刷新
//读取所有目录
//自动更新程序列表
string dir = Application.StartupPath;
List<FileInformation> list = DirectoryAllFiles.GetAllFiles(new System.IO.DirectoryInfo(dir));
if (list.Where(t => t.FileName.ToLower().Contains("android")).Any())
Console.WriteLine("true");
foreach (var item in list)
{
//Console.WriteLine(string.Format("文件名:{0}---文件目录{1}", item.FileName, item.FilePath));
if (item.FileName.Contains("1.exe"))
{
ListViewItem lvitem = new ListViewItem();
lvitem.SubItems[0].Text = item.FileName;
lvitem.SubItems.Add(item.FilePath); //strs[1] 目录
listView1.Items.Add(lvitem);
}
}
}
文章评论 本文章有个评论