4661.html
来自「以电子书的形式收集了VB一些常见问题解决方法,可以很方便的查找自己需要解决的问题」· HTML 代码 · 共 31 行
HTML
31 行
<html>
<head>
<title>Re: 请【笑儿】进来看看好吗?^_^..</title>
</head>
<body bgcolor="#FFFFFF" vlink="#808080">
<center>
<h1>Re: 请【笑儿】进来看看好吗?^_^..</h1>
</center>
<hr size=7 width=75%>
<hr size=7 width=75%><p>
Posted by 笑儿 on August 12, 1998 at 17:56:22:<p>
In Reply to: <a href="4633.html">请【笑儿】进来看看好吗?^_^..</a> posted by 小顺子 on August 12, 1998 at 03:21:38:<p>
老天, 你用OF_READ开启人家哪可能让你变更档案时间啊?<br>虽然我强烈建议不要使用OpenFile这个函式, 改用CreateFile这个函式, 但请你先用OF_READWRITE开开看好吗?<p>: 这个主要功能是由 API 更改档案的建立时间,<br>: 虽然我可以读取时间,也找了相对的 API<br>: 可是不论如何嚐试,就是无法写入,不知道<br>: SetFileTime Lib "kernel32" 更改档案时<br>: 间是要如何设定呢?<p>: <br>: '表单上有 Command1 和 Command2 , 并须要建立一个测试档案<br>: Option Explicit<p>: Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, _<br>: lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long<br>: Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) _<br>: As Long<p>: Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As _<br>: FileTime, lpSystemTime As SYSTEMTIME) As Long<br>: Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As _<br>: SYSTEMTIME, lpFileTime As FileTime) As Long<br>: <br>: Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, _<br>: lpCreationTime As FileTime, lpLastAccessTime As FileTime, _<br>: lpLastWriteTime As FileTime) As Long<br>: Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, _<br>: lpCreationTime As FileTime, lpLastAccessTime As FileTime, _<br>: lpLastWriteTime As FileTime) As Long<p>: Const OFS_MAXPATHNAME = 128<br>: Const OF_READ = &H0<br>: Dim FileHandle As Long<p>: Private lpReOpenBuff As OFSTRUCT<br>: Private Type OFSTRUCT<br>: cBytes As Byte<br>: fFixedDisk As Byte<br>: nErrCode As Integer<br>: Reserved1 As Integer<br>: Reserved2 As Integer<br>: szPathName(OFS_MAXPATHNAME) As Byte<br>: End Type<p>: Private ft As SYSTEMTIME<br>: Private Type SYSTEMTIME<br>: wYear As Integer<br>: wMonth As Integer<br>: wDayOfWeek As Integer<br>: wDay As Integer<br>: wHour As Integer<br>: wMinute As Integer<br>: wSecond As Integer<br>: wMilliseconds As Integer<br>: End Type<p>: Private Type FileTime<br>: dwLowDateTime As Long<br>: dwHighDateTime As Long<br>: End Type<p>: '更改档案时间资讯<br>: Private Sub Command1_Click()<br>: Dim cre As FileTime '建立<br>: Dim acc As FileTime '修改<br>: Dim wri As FileTime '存取<br>: Dim myfile As String '测试档案<br>: myfile = "f:\0000.txt"<br>: FileHandle = OpenFile(myfile, lpReOpenBuff, OF_READ) '先取得 File 的 Handle<br>: '这里要如何写呢?<br>: '我试了很多方法,可是档案的时间仍没有改变...<br>: Call SetFileTime(FileHandle, cre, acc, wri) '更改时间资料<br>: Call CloseHandle(FileHandle)<br>: End Sub<p>: '取得档案时间资讯<br>: Private Sub Command2_Click()<br>: Dim cre As FileTime '建立<br>: Dim acc As FileTime '修改<br>: Dim wri As FileTime '存取<br>: Dim mycr As Date '格林威治时间<br>: Dim myfile As String '测试档案<br>: myfile = "f:\0000.txt"<br>: FileHandle = OpenFile(myfile, lpReOpenBuff, OF_READ) '取得 File 的 Handle<br>: Call GetFileTime(FileHandle, cre, acc, wri) '取得时间资料<br>: Call CloseHandle(FileHandle)<br>: Call FileTimeToSystemTime(cre, ft) '转换时间资料结构<br>: mycr = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + _<br>: TimeSerial(ft.wHour, ft.wMinute, ft.wSecond) '转换时间格式<br>: MsgBox mycr<br>: End Sub<p>
<br>
<br><hr size=7 width=75%><p>
<a name="followups">Follow Ups:</a><br>
<ul><!--insert: 4661-->
<!--top: 4672--><li><a href="4672.html">CreateFile 和 OpenFile 的不同?</a> <b>小顺子</b> <i>04:44:35 8/13/98</i>
(<!--responses: 4672-->1)
<ul><!--insert: 4672-->
<!--top: 4673--><li><a href="4673.html">Re: CreateFile 和 OpenFile 的不同?</a> <b>笑儿</b> <i>05:09:11 8/13/98</i>
(<!--responses: 4673-->0)
<ul><!--insert: 4673-->
</ul><!--end: 4673-->
</ul><!--end: 4672-->
</ul><!--end: 4661-->
<br><hr size=7 width=75%><p>
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?