Nabídka portálu se při zobrazení článku přesouvá na konec pravého sloupce nabídek.
Informace o souboru pomocí API |
Autor: Kočí Marek
| Zdroj: API GUIDE
| Vytvořeno: 21.1.2003
| Publikováno: 21.1.2003
| Čtenářů: 2625
| Unikátních: 2551
|
Jak získat informace o souboru
Do modulu vložte
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
'
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Declare Function GetFileSize Lib "kernel32" _
(ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" _
(ByVal hFile As Long, lpCreationTime As FILETIME, _
lpLastAccessTime As FILETIME, _
lpLastWriteTime As FILETIME) As Long
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" (ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
lpSecurityAttributes As Long, _
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 Declare Function FileTimeToSystemTime _
Lib "kernel32" (lpFileTime As FILETIME, _
lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToLocalFileTime _
Lib "kernel32" (lpFileTime As FILETIME, _
lpLocalFileTime As FILETIME) As Long
Public Function FileInfo(ByVal sFileName As String, _
ByRef lFileSize As Long, _
ByRef dFileCreateDate As Date, _
Optional ByRef dFileCreateTime) _
As Boolean
Dim lngHandle As Long
Dim SHDirOp As SHFILEOPSTRUCT, lngLong As Long
Dim Ft1 As FILETIME, Ft2 As FILETIME
Dim SysTime As SYSTEMTIME
On Error Resume Next
lngHandle = CreateFile(sFileName, GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
ByVal 0&, OPEN_EXISTING, 0, 0)
lFileSize = GetFileSize(lngHandle, lngLong)
GetFileTime lngHandle, Ft1, Ft1, Ft2
FileTimeToLocalFileTime Ft2, Ft1
FileTimeToSystemTime Ft1, SysTime
dFileCreateDate = DateSerial(SysTime.wYear, _
SysTime.wMonth, _
SysTime.wDay)
dFileCreateTime = TimeSerial(SysTime.wHour, _
SysTime.wMinute, _
SysTime.wSecond)
CloseHandle lngHandle
If Err.Number <> 0 Then
FileInfo = False
Else
FileInfo = True
End If
End Function
Funkci pak použijete například takto:
Dim lSize As Long
Dim dCreate As Date
Dim dTime
If FileInfo("c:\001.bmp", lSize, _
dCreate, dTime) Then
MsgBox "Size = " & lSize & "bytes" & vbNewLine & _
"Create date = " & dCreate & vbNewLine & _
"Create time = " & dTime, vbOKOnly Or _
vbInformation, "Soubor info:"
End If
|