VB获得文件夹或文件的大小

Option Explicit

Private Sub Command1_Click()
Me.Print ByteAmount(“C:\1.txt”, 1, 0)
End Sub

Private Function ForWindow(ByVal Length As Double, Optional Nx As Long) As String '字节转换
Dim Strtxt(1) As String, Gtlng As Double
Gtlng = Length
If Gtlng >= 1073741824 Then
Strtxt(0) = FormatNumber(Gtlng / 1073741824, 2) & “GB”
ElseIf Gtlng >= 1048576 Then
Strtxt(0) = FormatNumber(Gtlng / 1048576, 2) & “MB”
ElseIf Gtlng >= 1024 Then
Strtxt(0) = FormatNumber(Gtlng / 1024, 2) & “KB”
Else
Strtxt(0) = Gtlng & “B”
End If
If Gtlng > 0 Then
Strtxt(1) = Format(Gtlng, “#,###,####,###”) & " 字节"
Else
Strtxt(1) = 0 & " 字节"
End If
If Nx = 0 Then
ForWindow = Strtxt(0) & SpaceKaTeX parse error: Expected 'EOF', got '&' at position 5: (1) &̲ "(" & Strtxt(1…(2) & Strtxt(0)
End If
End Function

Private Function ByteAmount(ByVal Path As String, Optional Result As Long, Optional FileType As Long)
Dim Fso As Object, B As Double
Set Fso = CreateObject(“Scripting.FileSystemObject”)
On Error GoTo Mistake
If FileType > 0 Then '文件夹
B = Fso.GetFolder(Path).Size '文件夹大小
’ Fso.GetFolder(Path).Files.Count '文件夹内包含的文件数量
Else
B = Fso.Getfile(Path).Size '文件大小
End If
ByteAmount = ForWindow(B, Result)
Mistake:
Set Fso = Nothing
End Function

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

键盘上的舞指

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值