您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關如何按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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。