如何使用 Visual Basic .net (vb.net) 根据文件夹中的文件大小对文件进行计数



我想根据文件的大小对文件夹中的文件进行计数。例如,小于 512KB 的文件数和大于 512KB 的文件数。请帮助我。

下面的子例程将帮助您获取计数

Sub GetFileDetails(ByVal sFolderPath As String, ByRef Filelessthan512KB As Integer, ByRef FileMorethan512KB As Integer)
        Dim sFiles() As String = Directory.GetFiles(sFolderPath)
        For Each file As String In sFiles
            Dim oFileDetails As New FileInfo(file)
            If (oFileDetails.Length / 1024) < 512 Then
                Filelessthan512KB = Filelessthan512KB + 1
            Else
                FileMorethan512KB = FileMorethan512KB + 1
            End If
        Next
    End Sub

最新更新