整理您的PC文件 [英] organize your PC files

查看:51
本文介绍了整理您的PC文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写C#代码以根据自己的类型对PC中的所有文件进行排序,并在treeview中显示所有文件.

how I can write C# code to sort all the files in my PC according to thier types and show all of them in treeview

推荐答案

.GetFiles,您会发现它具有重载,该重载将返回子目录中的所有文件以及指定的文件夹.
If you look at Directory.GetFiles, you will find it has an overload which returns all files in subdirectories as well as the specified folder.
string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);


然后使用Linq方法对它们进行排序将非常简单:


It would then be pretty simple to sort them using Linq methods:

var sorted = files.OrderBy(s => new FileInfo(s).Extension);


然后,您要做的就是以您喜欢的任何方式显示它们!


Then all you have to do is display them in whatever way your feel like!


这篇关于整理您的PC文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆