如何在所有本地计算机中查找所有目录? [英] how to find all directories in all local machine ?
本文介绍了如何在所有本地计算机中查找所有目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想使用c#在本地计算机上自动查找所有目录.
我已经使用下面显示的代码完成了此操作,该代码应选择一个节点以查找子目录,而我想自动执行此操作.
谁能帮我吗?
Hi all,
I want to automatically find all directories in a local machine using c#.
I have done this with the code shown below, which should select a node to find sub directory and I want to do this automatically.
Can anyone help me?
private void button2_Click(object sender, EventArgs e)
{
DriveInfo[] varDriveInfo = DriveInfo.GetDrives();
string[] SubElement = new string[varDriveInfo.Length];
TreeNode trd=new TreeNode();
for (int i = 0; i < varDriveInfo.Length; i++)
{
trd.Nodes.Add(varDriveInfo[i].ToString().Substring(0, 1));
treeView1.Nodes.Add(varDriveInfo[i].ToString().Substring(0, 1));
try
{
string[] subDirectory = Directory .GetDirectories (varDriveInfo[i] .ToString());
for (int j = 0; j < subDirectory.Length; j++)
{
treeView1.Nodes[i].Nodes.Add(subDirectory[j]);
}
}
catch
{ continue; }
}
}
code for find sub directory :
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
string[] subDirectory = Directory.GetDirectories(treeView1.SelectedNode.Text);
string[] ListFile = Directory.GetFiles(treeView1.SelectedNode.Text);
listBox1.Items.Clear();
foreach (string FileName in ListFile)
listBox1.Items.Add(FileName);
for (int j = 0; j < subDirectory.Length; j++)
try
{
treeView1.SelectedNode.Nodes.Add(subDirectory[j]);
}
catch
{ continue; }
}
catch { }
}
推荐答案
使用DirectoryInfo类.请参见此处 [
use DirectoryInfo class. See here[^] for information and a good example.
您应该使用递归来查找从C的起点开始的所有内容:\
http://support.microsoft.com/kb/303974 [ Directory Recursion c# [
You should use recursion to find everything from a starting point of C:\
http://support.microsoft.com/kb/303974[^]
Have a search for Directory Recursion c#[^]
这篇关于如何在所有本地计算机中查找所有目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文