利用属性获取文件目录
2015-11-21 09:39
176 查看
刚写出来的代码,测试了下,感觉很方便,给一个根目录就自动获取到下面所有的文件文件夹的树形结构
我是2015年11月21日上午9点36分独立写完并测试的代码,如果已经有人搞出来了那只能是巧合
。。
上代码:
免去了自己手写递归的麻烦。
.
我是2015年11月21日上午9点36分独立写完并测试的代码,如果已经有人搞出来了那只能是巧合
。。
上代码:
public class Folder { private string fullPath; public string FullPath { get { return this.fullPath; } set { if (value != this.fullPath) { if (!System.IO.Directory.Exists(value)) { return; } this.fullPath = value; System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(value); this.FileList = dirInfo.GetFiles() .Select(fileInfo => fileInfo.Name).ToList(); this.SubFolderList = dirInfo.GetDirectories() .Select(subDir => new Folder() { FullPath = subDir.FullName }).ToList(); } } } private List<string> fileList; public List<string> FileList { get { if (this.fileList == null) { this.fileList = new List<string>(); } return this.fileList; } set { this.fileList = value; } } private List<Folder> subFolderList; public List<Folder> SubFolderList { get { if (this.subFolderList == null) { this.subFolderList = new List<Folder>(); } return this.subFolderList; } set { this.subFolderList = value; } } }
免去了自己手写递归的麻烦。
.
相关文章推荐
- UI第九天:UITableView表视图
- Pyscripter为什么总报错?UnicodeEncodeError: 'ascii' codec can't encode characters in position
- 浅谈==和equals
- linux内核移植X86平台的例子
- ephemeral port的意义(ip_local_port_range )
- linux内核移植X86平台的例子
- linux内核移植X86平台的例子
- 光照模型
- linux内核移植X86平台的例子
- wampserver 配置详解
- android中json数据解析详解
- 一种信息更新方法及装置
- jdbc操作数据库基础
- 解决Prism中Region的GetView不起作用问题
- UISlider_滑块
- 8小时外实践系列(三)——玩玩github
- 物联网与嵌入式系统概论-week4-Networking and the Internet-Lesson3: Network Layers and MANETS
- 支付功能流程图
- 导出格式为PDF文档
- 导出格式为WORD文档