这篇文章将为大家详细讲解有关如何按VB.NET扩展名分组,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
VB.NET扩展名分组案例:
Public Class Form1 '按照扩展名分组文件 Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click Dim MyDir As String = Me.textBox1.Text Dim MyFiles As IEnumerable(Of System.IO.FileInfo) = GetFiles(MyDir) Dim MyQueryGroup = From MyFile In MyFiles _ Group MyFile By MyExt = MyFile.Extension.ToLower() _ Into MyFileGroup = Group _ Order By MyExt Me.listBox1.Items.Clear() For Each MyFileGroup In MyQueryGroup Me.listBox1.Items.Add("包含" + MyFileGroup.MyExt + "扩展名的文件如下:") For Each MyFileInfo In MyFileGroup.MyFileGroup Me.listBox1.Items.Add(MyFileInfo.Name) Next Me.listBox1.Items.Add("") Next End Sub '更多.net源码和实例,来自乐博网 www.lob.cn Function GetFiles(ByVal MyDir As String) As IEnumerable(Of System.IO.FileInfo) If (Not System.IO.Directory.Exists(MyDir)) Then Throw New System.IO.DirectoryNotFoundException() End If Dim MyFileNames As String() Dim MyFiles As List(Of System.IO.FileInfo) = New List(Of System.IO.FileInfo)() '查找指定目录下的所有子目录中的所有文件 'MyFileNames = System.IO.Directory.GetFiles(MyDir, "*.*", _ 'System.IO.SearchOption.AllDirectories) MyFileNames = System.IO.Directory.GetFiles(MyDir) For Each MyName As String In MyFileNames MyFiles.Add(New System.IO.FileInfo(MyName)) Next Return MyFiles End Function End Class
关于“如何按VB.NET扩展名分组”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。