//保存在磁盘的文件时间如何自己设定,而不想用系统的时间这个问题要用api函数SetFileTime解决: 【VB声明】 Private Declare Function SetFileTime Lib "kernel32" Alias "SetFileTime" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long【说明】 设置文件的创建、访问及上次修改时间 【返回值】 Long,非零表示成功,零表示失败。会设置GetLastError 【参数表】 hFile ---------- Long,系统文件句柄 lpCreationTime - FILETIME,文件的创建时间 lpLastAccessTime - FILETIME,文件上一次访问的时间 lpLastWriteTime - FILETIME,文件最近一次修改的时间例子: 'This project needs a Common Dialog box, named CDBox. ' (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T) ' and select Microsoft Common Dialog control) 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_WRITE = &H40000000 Private Const OPEN_EXISTING = 3 Private Const FILE_SHARE_READ = &H1 Private Const FILE_SHARE_WRITE = &H2 Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long Private Sub Form_Load() 'KPD-Team 1998 'URL: http://www.allapi.net/ '[email protected] Dim m_Date As Date, lngHandle As Long Dim udtFileTime As FILETIME Dim udtLocalTime As FILETIME Dim udtSystemTime As SYSTEMTIME m_Date = Format(Now, "DD-MM-YY") 'Set the dialog's title CDBox.DialogTitle = "Choose a file ..." 'Set the dialog's filter CDBox.Filter = "All Files (*.*)|*.*" 'Show the 'Open File'-dialog CDBox.ShowOpen udtSystemTime.wYear = Year(m_Date) udtSystemTime.wMonth = Month(m_Date) udtSystemTime.wDay = Day(m_Date) udtSystemTime.wDayOfWeek = WeekDay(m_Date) - 1 udtSystemTime.wHour = Hour(m_Date) udtSystemTime.wSecond = Second(m_Date) udtSystemTime.wMilliseconds = 0 ' convert system time to local time SystemTimeToFileTime udtSystemTime, udtLocalTime ' convert local time to GMT LocalFileTimeToFileTime udtLocalTime, udtFileTime ' open the file to get the filehandle lngHandle = CreateFile(CDBox.Filename, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0) ' change date/time property of the file SetFileTime lngHandle, udtFileTime, udtFileTime, udtFileTime ' close the handle CloseHandle lngHandle MsgBox "The date of the file '" + CDBox.Filename + "' has been changed to" + Str$(m_Date), vbInformation + vbOKOnly, App.Title End Sub
'以下是读取Binary file的程式 Dim Buff() as ByteOpen "d:\csys\8504\ctc" For Binary Access Read As #1 ReDim Buff(267)Do While Not EOF(1) Get #1, , Buff '每次读268个byte进来 'Call 处理Buff 的Routine Loop Close #1'以下是写入Binary file的程式 Dim Buff() As Byte Open "c:\tc" For Binary Access Write As #1 ReDim Buff(10) Buff = StrConv("这是一个11", vbFromUnicode) Put #1, , BuffReDim Buff(1) Buff(0) = 210 Buff(1) = 70 Put #1, , Buff Close #1 End Sub
2)我不知道,可能要建立后再用 api 来修改
【VB声明】
Private Declare Function SetFileTime Lib "kernel32" Alias "SetFileTime" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long【说明】
设置文件的创建、访问及上次修改时间 【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError 【参数表】
hFile ---------- Long,系统文件句柄 lpCreationTime - FILETIME,文件的创建时间 lpLastAccessTime - FILETIME,文件上一次访问的时间 lpLastWriteTime - FILETIME,文件最近一次修改的时间例子:
'This project needs a Common Dialog box, named CDBox.
' (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
' and select Microsoft Common Dialog control)
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_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'[email protected]
Dim m_Date As Date, lngHandle As Long
Dim udtFileTime As FILETIME
Dim udtLocalTime As FILETIME
Dim udtSystemTime As SYSTEMTIME
m_Date = Format(Now, "DD-MM-YY") 'Set the dialog's title
CDBox.DialogTitle = "Choose a file ..."
'Set the dialog's filter
CDBox.Filter = "All Files (*.*)|*.*"
'Show the 'Open File'-dialog
CDBox.ShowOpen udtSystemTime.wYear = Year(m_Date)
udtSystemTime.wMonth = Month(m_Date)
udtSystemTime.wDay = Day(m_Date)
udtSystemTime.wDayOfWeek = WeekDay(m_Date) - 1
udtSystemTime.wHour = Hour(m_Date)
udtSystemTime.wSecond = Second(m_Date)
udtSystemTime.wMilliseconds = 0 ' convert system time to local time
SystemTimeToFileTime udtSystemTime, udtLocalTime
' convert local time to GMT
LocalFileTimeToFileTime udtLocalTime, udtFileTime
' open the file to get the filehandle
lngHandle = CreateFile(CDBox.Filename, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
' change date/time property of the file
SetFileTime lngHandle, udtFileTime, udtFileTime, udtFileTime
' close the handle
CloseHandle lngHandle
MsgBox "The date of the file '" + CDBox.Filename + "' has been changed to" + Str$(m_Date), vbInformation + vbOKOnly, App.Title
End Sub
Dim Buff() as ByteOpen "d:\csys\8504\ctc" For Binary Access Read As #1
ReDim Buff(267)Do While Not EOF(1)
Get #1, , Buff '每次读268个byte进来
'Call 处理Buff 的Routine
Loop
Close #1'以下是写入Binary file的程式
Dim Buff() As Byte
Open "c:\tc" For Binary Access Write As #1
ReDim Buff(10)
Buff = StrConv("这是一个11", vbFromUnicode)
Put #1, , BuffReDim Buff(1)
Buff(0) = 210
Buff(1) = 70
Put #1, , Buff
Close #1
End Sub