Option Explicit Private Declare Function OpenFile Lib "kernel32.dll" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As LongPrivate Declare Function GetFileTime Lib "kernel32.dll" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As LongPrivate Declare Function FileTimeToLocalFileTime Lib "kernel32.dll" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As LongPrivate Declare Function FileTimeToSystemTime Lib "kernel32.dll" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As LongPrivate Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As LongPrivate Const OF_READ As Long = &H0Private Type FILETIMEdwLowDateTime As LongdwHighDateTime As LongEnd Type Private Type OFSTRUCTcBytes As BytefFixedDisk As BytenErrCode As IntegerReserved1 As IntegerReserved2 As IntegerszPathName(128) As Byte 'OFS_MAXPATHNAMEEnd Type Private Type SYSTEMTIMEwYear As IntegerwMonth As IntegerwDayOfWeek As IntegerwDay As IntegerwHour As IntegerwMinute As IntegerwSecond As IntegerwMilliseconds As IntegerEnd Type Private Sub Command1_Click()Dim hFile As Long ' Манипулятор на файл.'Если имя файла больше 128 символов, то надо использовать CreateFileDim ctime As FILETIME ' Время создания файлаDim atime As FILETIME ' Время последнего открытия файлаDim mtime As FILETIME ' Время последнего изменения файлаDim Cthetime As SYSTEMTIME ' Структура для конвертирования формата времени создания файлаDim Athetime As SYSTEMTIME ' Структура для конвертирования формата времени последнего открытия файлаDim Mthetime As SYSTEMTIME ' Структура для конвертирования формата времени последнего изменения файлаDim ofOpen As OFSTRUCT ' Структура для открытия файлаDim rc As LongofOpen.cBytes = Len(ofOpen) ' Получаем манипулятор файла hFile = OpenFile("C:\MyFile.txt", ofOpen, OF_READ) If hFile = -1 ThenMsgBox "Файл не найден!", vbInformation Exit Sub End If 'Узнаем время создания, открытия, изменения файла rc = GetFileTime(hFile, ctime, atime, mtime) 'Конвертируем время создания в локальный часовой пояс rc = FileTimeToLocalFileTime(ctime, ctime) rc = FileTimeToLocalFileTime(atime, atime) rc = FileTimeToLocalFileTime(mtime, mtime) Ответить
|