编程语言

img iwebsms

递归统计指定目录下所有文件容量总和

发表于2004/9/28 19:37:00  893人阅读

 

Public Class ShowDirSize

    '递归统计指定目录下所有文件容量总和

    Public Shared Function DirSize(ByVal d As IO.DirectoryInfo) As Long

        Dim Size As Long = 0

        ' 统计本目录下所有文件容量总和

        Dim fis As IO.FileInfo() = d.GetFiles()

        Dim fi As IO.FileInfo

        For Each fi In fis

            Size += fi.Length

        Next fi

        ' 递归统计所有子目录下所有文件容量总和

        Dim dis As IO.DirectoryInfo() = d.GetDirectories()

        Dim di As IO.DirectoryInfo

        For Each di In dis

            Size += DirSize(di)

        Next di

        Return Size

    End Function

End Class


        '调用代码

        Dim dir As New System.IO.DirectoryInfo(TxtDir.Text)

        TxtMessage.Text = ShowDirSize.DirSize(dir)

阅读全文
0 0

相关文章推荐

img
取 消
img