查找文件的父母或父母目录 [英] Find parent or parents directories of a file
本文介绍了查找文件的父母或父母目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件说xyz.doc。我想找到父母/这个文件的父母,这样我可以在树视图绑定。我们怎样才能achive呢?
我有一个由code获得FileInfo类
的FileInfo [] =文件Directory.GetFiles(路径,*。*);
解决方案
尝试
LookingFor(新FileInfo的(路径)名为.directory));公共无效LookingFor(DirectoryInfo的DIR)
{
如果(dir.Parent == NULL)
返回;
//添加家长的ListView
LookingFor(dir.Parent);
}
I have a file say xyz.doc .I want to find the parent /Parents of this file ,so that i can bind it in a tree view . How can we achive this ?
I have the fileinfo class which is obtained by the code
FileInfo[] files = Directory.GetFiles(path,"*.*);
解决方案
Try
LookingFor(new FileInfo(path).Directory));
public void LookingFor(DirectoryInfo dir)
{
if (dir.Parent == null)
return;
// Add parent to ListView
LookingFor(dir.Parent);
}
这篇关于查找文件的父母或父母目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文