如何取得文件的最后一次修改的时间?

handyworkroom 2003-10-02 08:11:09
如题
...全文
318 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
goodname008 2003-10-03
  • 打赏
  • 举报
回复
真是个好哥哥,呵呵。 :)
pigpag 2003-10-03
  • 打赏
  • 举报
回复
有QQ号,送给我妹妹了
goodname008 2003-10-03
  • 打赏
  • 举报
回复
真奇怪 pigpag(噼里啪啦) 怎么会没有QQ,现在还能申请吗?
pigpag 2003-10-03
  • 打赏
  • 举报
回复
Neither是我

MSN: pigpag@msn.com
本人无QQ,勿见怪
goodname008 2003-10-03
  • 打赏
  • 举报
回复
呵呵,我可不是什么大侠。
QQ:49743105
handyworkroom 2003-10-03
  • 打赏
  • 举报
回复
to goodname008(卢培培,LPP Software) and pigpag(噼里啪啦)
两位大侠,能不能留下联系方式呀,谢谢
goodname008 2003-10-03
  • 打赏
  • 举报
回复
:)
pigpag 2003-10-03
  • 打赏
  • 举报
回复
//还是FileDateTime简单,FSO还得引用再声明什么的,这个函数来得多快。 :)

“简单”的含义不同。我也提倡“绿色”地!
pigpag 2003-10-03
  • 打赏
  • 举报
回复
Dim FSO As New FileSystemObject
FSO.GetFile("文件名").DateLastModified,即可返回上次修改日期。
goodname008 2003-10-03
  • 打赏
  • 举报
回复
还是FileDateTime简单,FSO还得引用再声明什么的,这个函数来得多快。 :)
pigpag 2003-10-03
  • 打赏
  • 举报
回复
FileSystemObject最简单
goodname008 2003-10-03
  • 打赏
  • 举报
回复
FileDateTime 函数


返回一个 Variant (Date),此为一个文件被创建或最后修改后的日期和时间。

语法

FileDateTime(pathname)

必要的 pathname 参数是用来指定一个文件名的字符串表达式。pathname 可以包含目录或文件夹、以及驱动器。
goodname008 2003-10-03
  • 打赏
  • 举报
回复
' 还是这个方便些。

Option Explicit

Private Sub Command1_Click()
Debug.Print FileDateTime("c:\123.txt")
End Sub
goodname008 2003-10-03
  • 打赏
  • 举报
回复
' 假设获得c:\123.txt的时间

Option Explicit
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Const OF_CANCEL = &H800
Private Const OF_CREATE = &H1000
Private Const OF_DELETE = &H200
Private Const OF_EXIST = &H4000
Private Const OF_PARSE = &H100
Private Const OF_PROMPT = &H2000
Private Const OF_READ = &H0
Private Const OF_READWRITE = &H2
Private Const OF_REOPEN = &H8000
Private Const OF_SHARE_COMPAT = &H0
Private Const OF_SHARE_DENY_NONE = &H40
Private Const OF_SHARE_DENY_READ = &H30
Private Const OF_SHARE_DENY_WRITE = &H20
Private Const OF_SHARE_EXCLUSIVE = &H10
Private Const OF_VERIFY = &H400
Private Const OF_WRITE = &H1
Private Const OFS_MAXPATHNAME = 128
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 Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Private Sub Command1_Click()
Dim fStruct As OFSTRUCT
Dim CreationTime As FILETIME
Dim LastAccessTime As FILETIME
Dim LastWriteTime As FILETIME
Dim hFile As Long
With fStruct
.cBytes = 136
End With
hFile = OpenFile("c:\123.txt", fStruct, OF_READ)
GetFileTime hFile, CreationTime, LastAccessTime, LastWriteTime
Debug.Print CreationTime.dwHighDateTime
Debug.Print CreationTime.dwLowDateTime
End Sub

但dwHighDateTime和dwLowDateTime不是我们一眼能看懂的,得转换。

MSDN是这样说的:

FILETIME
The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.

typedef struct _FILETIME { // ft
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;

Members
dwLowDateTime
Specifies the low-order 32 bits of the file time.
dwHighDateTime
Specifies the high-order 32 bits of the file time.
Remarks
It is not recommended that you add and subtract values from the FILETIME structure to obtain relative times. Instead, you should

Copy the resulting FILETIME structure to a LARGE_INTEGER structure.
Use normal 64-bit arithmetic on the LARGE_INTEGER value.
handyworkroom 2003-10-03
  • 打赏
  • 举报
回复
to goodname008(卢培培,LPP Software) :
你给了我两个API函数,我不知道应该怎么调用它们,能不能给我一个调用它的代码呀,谢谢!
goodname008 2003-10-02
  • 打赏
  • 举报
回复
to kmzs(.:RNPA:.山水岿濛) :
楼主是要获得最后一次修改的时间。
kmzs 2003-10-02
  • 打赏
  • 举报
回复
FileDateTime(FileName)不就行了,搞那么复杂干吗???
goodname008 2003-10-02
  • 打赏
  • 举报
回复
FILETIME

类型定义
Type FILETIME ' 8 Bytes
dwLowDateTime As Long
dwHighDateTime As Long
End Type
说明
windows提供了一种特殊的机制,可以记录文件的访问及创建时间。在win32环境中,这些信息以64位值的形式保存,量度的是自1601年1月1日以来经历的100ns时间单位数量(64-bit number specifying the elapsed time since January 1, 1601, in 100-nanosecond increments.)
字段表
字段 类型及说明
dwLowDateTime Long,Low and high-order 32 bits of the file time
dwHighDateTime
注解
文件时间在系统中通常用“协同世界时间”(UTC)的格式保存,但同时提供了在UTC及本地时间之间转换的函数。FILETIME结构里可包含UTC或本地时间——由我们自行决定在结构中包含什么时间

goodname008 2003-10-02
  • 打赏
  • 举报
回复
GetFileTime

VB声明
Declare Function GetFileTime Lib "kernel32" Alias "GetFileTime" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
说明
取得指定文件的时间信息
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
hFile Long,文件的句柄
lpCreationTime FILETIME,用于装载文件的创建时间
lpLastAccessTime FILETIME,用于装载文件上一次访问的时间(FAT文件系统不支持这一特性)
lpLastWriteTime FILETIME,用于装载文件上一次修改的时间
注解
如果不需要特定的信息,那么lpCreationTime,lpLastAccessTime,lpLastWriteTime都可以设置为零(用ByVal As Long)。这个函数返回的文件时间采用UTC格式



goodname008 2003-10-02
  • 打赏
  • 举报
回复
' 用这个函数

Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧