有时API确实很好很强大。。。但是,VB可以做的事情,从来就不需要别人。
输入文件路径,即可返回文件的字节大小!
'BY Coo_boi
Private Function GetFileVolume(ByVal lpFileName As String) As Long
If Dir(lpFileName) = "" Then Exit Function
Dim FF As Long
FF = FreeFile()
Open lpFileName For Binary Access Read As #FF
GetFileVolume = LOF(FF)
Close #FF
End Function
工程-引用-Microsoft scripting runtime后;
Private Sub Form_Load()
Dim fso1 As New FileSystemObject
Dim folder1 As Folder
Set folder1 = fso1.GetFolder("c:\")
Msgbox folder1.Size & "Bytes"
End Sub
Dim infoReader As System.IO.FileInfo
infoReader = My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
MsgBox("File is " & infoReader.Length & " bytes.")
double貌似比long可以大很多。
获取文件句柄貌似可以用API - CreateFile,你自己试试