您好,登錄后才能下訂單哦!
本篇文章為大家展示了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 = GetFiles(MyDir) Dim MyQuery = From MyFile In MyFiles _ Order By (GetLength(MyFile)) _ Select MyFile Me.dataGridView1.DataSource = MyQuery.ToArray() End Sub 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 Function GetLength(ByVal MyFileInfo As System.IO.FileInfo) As Long Dim MyLength As Long = 0 Try '更多.net源碼和實例 MyLength = MyFileInfo.Length Catch ex As System.IO.FileNotFoundException MyLength = 0 End Try Return MyLength End Function End Class
上述內容就是VB.NET中怎么對文件排序,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。