本文介绍了整理您的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

推荐答案

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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 14:29