非递归的遍历,使用栈来存储当前访问结点的子节点信息,用于接下来访问。
通过栈保存还没有访问的目录结点
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;
using System.Collections.Generic;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog()==DialogResult.OK)
{
string path = folderBrowserDialog1.SelectedPath;
this.textBox1.Text = path;
TreeNode node=new TreeNode("文件");
this.treeView1.Nodes.Add(node);
DirectoryInfo dir=new DirectoryInfo(pa