我完成这个简单的程序有点困难:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Find_directories
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txtbox_find_TextChanged(object sender, EventArgs e)
{
}
private void button_browse_Click(object sender, EventArgs e)
{
String v = txtbox_find.Text;
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
{
FileName = @"c:\" + v,
UseShellExecute = true,
Verb = "open"
});
}
}
}
目前应用程序只打开c:root中包含的目录,但我想要的是查看目录c:并使用资源管理器打开插入文本框的目录/子目录(txtbox_find)。
示例:我放入文本框" drivers"单击浏览按钮,应用程序将搜索并打开资源管理器。
答案 0 :(得分:1)
答案 1 :(得分:0)
这将为你做。
全局创建字符串列表
public static List<string> pathsToFind = new List<string>();
将其放入按钮点击事件
string originalPath = @"C:\";
string findPath = txtbox_find.Text;
FolderNames(originalPath);
List<string> paths = pathsToFind;
IEnumerable<string> filteredPaths = paths.Where(x => x.Remove(0,x.LastIndexOf('\\') + 1) == findPath);
foreach (string path in filteredPaths)
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
{
FileName = "explorer.exe",
Arguments = path,
UseShellExecute = true,
Verb = "open"
});
}
然后创建一个替代方法。我们把它称为FolderNames。
public static void FolderNames(string path)
{
pathsToFind.Add(path);
DirectoryInfo dir = new DirectoryInfo(path);
try
{
foreach (DirectoryInfo info in dir.GetDirectories())
{
folderNames(info.FullName);
}
}
catch (Exception)
{
}
}