# Re: 请【笑儿】进来看看好吗？^_^..

Posted by 笑儿 on August 12, 1998 at 17:56:22:

In Reply to: 请【笑儿】进来看看好吗？^_^.. posted by 小顺子 on August 12, 1998 at 03:21:38:

老天, 你用OF_READ开启人家哪可能让你变更档案时间啊?
虽然我强烈建议不要使用OpenFile这个函式, 改用CreateFile这个函式, 但请你先用OF_READWRITE开开看好吗?

: 这个主要功能是由 API 更改档案的建立时间，
: 虽然我可以读取时间，也找了相对的 API
: 可是不论如何嚐试，就是无法写入，不知道
: SetFileTime Lib "kernel32"　更改档案时
: 间是要如何设定呢？

:
: '表单上有 Command1 和 Command2 , 并须要建立一个测试档案
: Option Explicit

: Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, _
: lpReOpenBuff As OFSTRUCT, ByVal wStyle 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 SystemTimeToFileTime Lib "kernel32" (lpSystemTime As _
: SYSTEMTIME, lpFileTime As FileTime) 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 GetFileTime Lib "kernel32" (ByVal hFile As Long, _
: lpCreationTime As FileTime, lpLastAccessTime As FileTime, _
: lpLastWriteTime As FileTime) As Long

: Const OFS_MAXPATHNAME = 128
: Const OF_READ = &H0
: Dim FileHandle As Long

: Private lpReOpenBuff As OFSTRUCT
: 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 ft As SYSTEMTIME
: 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 Type FileTime
: dwLowDateTime As Long
: dwHighDateTime As Long
: End Type

: '更改档案时间资讯
: Private Sub Command1_Click()
: Dim cre As FileTime '建立
: Dim acc As FileTime '修改
: Dim wri As FileTime '存取
: Dim myfile As String '测试档案
: myfile = "f:\0000.txt"
: FileHandle = OpenFile(myfile, lpReOpenBuff, OF_READ) '先取得 File 的 Handle
: '这里要如何写呢?
: '我试了很多方法,可是档案的时间仍没有改变...
: Call SetFileTime(FileHandle, cre, acc, wri) '更改时间资料
: Call CloseHandle(FileHandle)
: End Sub

: '取得档案时间资讯
: Private Sub Command2_Click()
: Dim cre As FileTime '建立
: Dim acc As FileTime '修改
: Dim wri As FileTime '存取
: Dim mycr As Date '格林威治时间
: Dim myfile As String '测试档案
: myfile = "f:\0000.txt"
: FileHandle = OpenFile(myfile, lpReOpenBuff, OF_READ) '取得 File 的 Handle
: Call GetFileTime(FileHandle, cre, acc, wri) '取得时间资料
: Call CloseHandle(FileHandle)
: Call FileTimeToSystemTime(cre, ft) '转换时间资料结构
: mycr = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + _
: TimeSerial(ft.wHour, ft.wMinute, ft.wSecond) '转换时间格式
: MsgBox mycr
: End Sub

Follow Ups:

- CreateFile 和 OpenFile 的不同? 小顺子 04:44:35 8/13/98 (1)
  - Re: CreateFile 和 OpenFile 的不同? 笑儿 05:09:11 8/13/98 (0)