ftCreationTime As FILETIME ' - это то что тебе нужно
User-defined type not defined
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type OFSTRUCTREC
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Public Type FILETIMEREC
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type FILETIME
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
Public Declare Function FileTimeToSystemTime Lib "kernel32" _
(lpfileTime As FILETIMEREC, lpSystemTime As FILETIME) As Long
Public Declare Function GetFileTime Lib "kernel32" (ByVal _
hFile As Long, lpCreationTime As FILETIMEREC, lpLastAccessTime _
As FILETIMEREC, lpLastWriteTime As FILETIMEREC) As Long
Public Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As _
String, lpReOpenBuff As OFSTRUCTREC, ByVal wStyle As Long) As Long
Public Declare Function hread Lib "kernel32" Alias "_hread" _
(ByVal hFile As Long, lpBuffer As Any, ByVal lBytes As Long) As Long
Public Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal _
hFile As Long) As Long
'в модуль
Sub Form_Load()
Command1.Caption = "&Get file access time"
Text1.Text = "C:\AUTOEXEC.BAT"
End Sub
Private Sub Command1_Click()
Dim sInpFile As String
Dim hFile As Integer
Dim FileStruct As OFSTRUCTREC
Dim iRC As Integer
Dim CreationTime As FILETIMEREC
Dim LastAccessTime As FILETIMEREC
Dim LastWriteTime As FILETIMEREC
Dim SystemTime As SYSTEMTIMEREC
sInpFile = Trim(Text1.Text)
' check that the file exists
If Len(Dir(sInpFile)) = 0 Then
MsgBox "Can't find the file", vbExclamation
Exit Sub
End If
' Open it to get a stream handle
hFile = OpenFile(sInpFile, FileStruct, OF_READ Or OF_SHARE_DENY_NONE)
If hFile = 0 Then
MsgBox "Can't open the file", vbExclamation
Exit Sub
End If
If GetFileTime(hFile, CreationTime, _
LastAccessTime, LastWriteTime) Then
' massage time into format that we can use
If Not FileTimeToSystemTime(LastAccessTime, SystemTime) Then
Print "Year of file :" & SystemTime.wYear
Print "Month of File :" & SystemTime.wMonth
Print "Day of File :" & SystemTime.wDay
Else
MsgBox "FileTimeToSystemTime Failed"
End If
Else
MsgBox "GetFileTime Failed"
End If
iRC = lclose(hFile)
End Sub
'в форму
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
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_READ As Long = &H80000000
Private Const OPEN_EXISTING = 3
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject 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 Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetFileTime Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpCreationTime As FILETIME, ByRef lpLastAccessTime As FILETIME, ByRef lpLastWriteTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32.dll" (ByRef lpFileTime As FILETIME, ByRef lpSystemTime As SYSTEMTIME) As Long
Private Sub Form_Load()
Dim hFile As Long, s As String
Dim CreationTime As FILETIME, LastAccessTime As FILETIME, LastWriteTime As FILETIME, SysTime As SYSTEMTIME
hFile = CreateFile("C:\autoexec.bat", GENERIC_READ, 0, ByVal 0, OPEN_EXISTING, 0, 0)
If hFile = -1 Then
MsgBox "Ошибка доступа к файлу"
Else
Call GetFileTime(hFile, CreationTime, LastAccessTime, LastWriteTime)
Call CloseHandle(hFile)
Call FileTimeToSystemTime(CreationTime, SysTime)
s = "Файл создан: " & SysTime.wDay & "." & SysTime.wMonth & "." & SysTime.wYear & vbCr
Call FileTimeToSystemTime(LastAccessTime, SysTime)
s = s & "LastAccessTime: " & SysTime.wDay & "." & SysTime.wMonth & "." & SysTime.wYear & vbCr
Call FileTimeToSystemTime(LastWriteTime, SysTime)
s = s & "LastWriteTime: " & SysTime.wDay & "." & SysTime.wMonth & "." & SysTime.wYear
MsgBox s
End If
End Sub
Сейчас этот форум просматривают: AhrefsBot, Google-бот, SemrushBot и гости: 159