Private Const OFS_MAXPATHNAME = 128
Private Const OF_READ = &H0
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Private Type FileTime
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type BY_HANDLE_FILE_INFORMATION
dwFileAttributes As Long
ftCreationTime As FileTime
ftLastAccessTime As FileTime
ftLastWriteTime As FileTime
dwVolumeSerialNumber As Long
nFileSizeHigh As Long
nFileSizeLow As Long
nNumberOfLinks As Long
nFileIndexHigh As Long
nFileIndexLow As Long
End Type
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Sub Command1_Click()
Dim FileHandle As Long
Dim FileInfo As BY_HANDLE_FILE_INFORMATION
Dim lpReOpenBuff As OFSTRUCT
FileHandle = OpenFile("d:\office1.cab", lpReOpenBuff, OF_READ)
Call GetFileInformationByHandle(FileHandle, FileInfo)
Call CloseHandle(FileHandle)
Dim c As Currency
CopyMemory ByVal VarPtr(c), ByVal VarPtr(FileInfo.nFileSizeLow), ByVal 4&
CopyMemory ByVal VarPtr(c) + 4, ByVal VarPtr(FileInfo.nFileIndexHigh), ByVal 4&
MsgBox FormatNumber(c * 10000, 0, , , vbTrue) & "(bytes)"
End Sub
Private Const OF_READ = &H0
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Private Type FileTime
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type BY_HANDLE_FILE_INFORMATION
dwFileAttributes As Long
ftCreationTime As FileTime
ftLastAccessTime As FileTime
ftLastWriteTime As FileTime
dwVolumeSerialNumber As Long
nFileSizeHigh As Long
nFileSizeLow As Long
nNumberOfLinks As Long
nFileIndexHigh As Long
nFileIndexLow As Long
End Type
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Sub Command1_Click()
Dim FileHandle As Long
Dim FileInfo As BY_HANDLE_FILE_INFORMATION
Dim lpReOpenBuff As OFSTRUCT
FileHandle = OpenFile("d:\office1.cab", lpReOpenBuff, OF_READ)
Call GetFileInformationByHandle(FileHandle, FileInfo)
Call CloseHandle(FileHandle)
Dim c As Currency
CopyMemory ByVal VarPtr(c), ByVal VarPtr(FileInfo.nFileSizeLow), ByVal 4&
CopyMemory ByVal VarPtr(c) + 4, ByVal VarPtr(FileInfo.nFileIndexHigh), ByVal 4&
MsgBox FormatNumber(c * 10000, 0, , , vbTrue) & "(bytes)"
End Sub
解决方案 »
- 如何从txt文件的特定的行里取数据并写入数据到特定的行
- 十万火急。。。在线等待之中{关于MSHFlexGrid控件}
- 请教VB与pop3 服务器连接的问题
- 如何读取网上的文本文件??
- 求AES加密算法源码
- listview里那一个属性是区分listview里有无内容的?
- 关于数据库中某字段的选项的使用问题(高分,请看清内容再答)
- msvcrt.dll这个东西是干什么用的?
- 在生成.chm格式的帮助文件时,为什么大多数都不支持中文,谁知道哪个能支持中文吗?
- 用vb泡MM,团结就是力量
- 如何不让 Sleep键 休眠电脑?(How to disable the keyboard's sleep key)
- 有关用程序设置EXCEL页面设置的问题,急,,,,,求救
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type BY_HANDLE_FILE_INFORMATION
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
dwVolumeSerialNumber As Long
nFileSizeHigh As Long
nFileSizeLow As Long
nNumberOfLinks As Long
nFileIndexHigh As Long
nFileIndexLow As Long
End Type
Private Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
Dim hFile As Long, FileInfo As BY_HANDLE_FILE_INFORMATION
'create a handle to the file 'c:\autoexec.bat'
hFile = CreateFile("c:\autoexec.bat", 0, 0, ByVal 0&, OPEN_EXISTING, 0, ByVal 0&)
'retrieve the file information
GetFileInformationByHandle hFile, FileInfo
'close the handle
CloseHandle hFile
'show the result
MsgBox "File size: " + CStr(FileInfo.nFileSizeLow), vbInformation
End SubConst GENERIC_READ = &H80000000
Const FILE_SHARE_READ = &H1
Const OPEN_EXISTING = 3
Const FILE_TYPE_CHAR = &H2
Const FILE_TYPE_DISK = &H1
Const FILE_TYPE_PIPE = &H3
Const FILE_TYPE_UNKNOWN = &H0
Private Declare Function GetFileType Lib "kernel32" (ByVal hFile As Long) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetFileSizeEx Lib "kernel32" (ByVal hFile As Long, lpFileSize As Currency) As Boolean
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Form_Paint()
Dim hFile As Long, nSize As Currency, sSave As String
'open the file
hFile = CreateFile("c:\autoexec.bat", GENERIC_READ, FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, ByVal 0&, ByVal 0&)
'get the filesize
GetFileSizeEx hFile, nSize
'retrieve the file type
Select Case GetFileType(hFile)
Case FILE_TYPE_UNKNOWN
sSave = "The type of the specified file is unknown"
Case FILE_TYPE_DISK
sSave = "The specified file is a disk file"
Case FILE_TYPE_CHAR
sSave = "The specified file is a character file, typically an LPT device or a console"
Case FILE_TYPE_PIPE
sSave = "The specified file is either a named or anonymous pipe"
End Select
'close the file
CloseHandle hFile
MsgBox "File Type: " + sSave + vbCrLf + "Size:" + Str$(nSize * 10000) + " bytes"
End Sub
vb.netImports System
Imports System.IO
Public Module modmain
Sub Main()
Dim MyFile as new FileInfo ("c:\autoexec.bat")
Console.WriteLine("The length of autoexec.bat is " _
+ MyFile.Length.ToString + " bytes.")
End Sub
End Module