文件操作(树形)
TreeNode trn;
trn = treeView1.Nodes.Add("打开查找");
getfiles(ppath, trn);
#region 递归
void getfiles(string path, TreeNode tn)
{
try
{
List<string> fi = Directory.GetFiles(path).ToList<string>();
foreach (var item in fi)
{
i++;
TreeNode tnn = tn.Nodes.Add(Path.GetFileName(item));
tnn.Tag = item;
// treeView1.Nodes[0].Text = "打开查找其有:" + i + " 个文件 " + j + "个文件夹";
}
List<string> dr = Directory.GetDirectories(path).ToList<string>();
if (dr.Count == 0)
{
if (th != null)
{
txtsb.Text = "执行完毕";
th.Abort();
}
}
foreach (var item in dr)
{
j++;
TreeNode tnn = tn.Nodes.Add(Path.GetFileName(item));
// treeView1.Nodes[0].Text = "打开查找其有:" + i + " 个文件 " + j + "个文件夹";
getfiles(item, tnn);
}
}
catch (Exception ex)
{
// txtsb.AppendText(ex.Message);
}
}
#endregion