webdiskshare.vb
来自「是可以运行的电子光盘 有程序与PPT介绍 对于学习VB。NET的有参考意义」· VB 代码 · 共 41 行
VB
41 行
Imports Microsoft.VisualBasic
Imports System.io
Public Module WebDiskShare
Public C_LargeUseDir As Long = 1024 * 1024 * 4
Public C_LargeManagerDir As Long = 1024 * 1024 * 20
'获取用户目录的大小
Public Function GetDirectorySize(ByVal thePath As String) As Long
Dim dirSize As Long
Dim dir As DirectoryInfo = New DirectoryInfo(thePath)
' Add the size of each file
Dim theFile As FileInfo
For Each theFile In dir.GetFiles()
dirSize = dirSize + theFile.Length
' Add the size of each subdirectory, retrieved by
' recursively calling this same function
Dim subDir As DirectoryInfo
For Each subDir In dir.GetDirectories
dirSize = dirSize + GetDirectorySize(subDir.FullName)
Next
Next
Return dirSize
End Function
Public Function FormatSize(ByVal fileSize As Double) As String
If fileSize < 1024 Then
Return String.Format("{0:N0} B", fileSize)
ElseIf (fileSize < 1024 * 1024) Then
Return String.Format("{0:N2} KB", fileSize / 1024)
Else
Return String.Format("{0:N2} MB", fileSize / (1024 * 1024))
End If
End Function
End Module
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?