如题

解决方案 »

  1.   

    ' 用这个函数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
      

  2.   

    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格式
     
      

  3.   

    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或本地时间——由我们自行决定在结构中包含什么时间
     
      

  4.   

    FileDateTime(FileName)不就行了,搞那么复杂干吗???
      

  5.   

    to kmzs(.:RNPA:.山水岿濛) :
    楼主是要获得最后一次修改的时间。
      

  6.   

    to goodname008(卢培培,LPP Software) :
    你给了我两个API函数,我不知道应该怎么调用它们,能不能给我一个调用它的代码呀,谢谢!
      

  7.   

    ' 假设获得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 TypePrivate 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. 
    Res
    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.
      

  8.   

    ' 还是这个方便些。Option ExplicitPrivate Sub Command1_Click()
    Debug.Print FileDateTime("c:\123.txt")
    End Sub
      

  9.   

    FileDateTime 函数
          返回一个 Variant (Date),此为一个文件被创建或最后修改后的日期和时间。语法FileDateTime(pathname)必要的 pathname 参数是用来指定一个文件名的字符串表达式。pathname 可以包含目录或文件夹、以及驱动器。
      

  10.   

    还是FileDateTime简单,FSO还得引用再声明什么的,这个函数来得多快。  :)
      

  11.   

    Dim FSO As New FileSystemObject
    FSO.GetFile("文件名").DateLastModified,即可返回上次修改日期。
      

  12.   

    //还是FileDateTime简单,FSO还得引用再声明什么的,这个函数来得多快。  :)“简单”的含义不同。我也提倡“绿色”地!
      

  13.   

    to goodname008(卢培培,LPP Software) and pigpag(噼里啪啦) 
    两位大侠,能不能留下联系方式呀,谢谢
      

  14.   

    Neither是我MSN: [email protected]
    本人无QQ,勿见怪
      

  15.   

    真奇怪 pigpag(噼里啪啦) 怎么会没有QQ,现在还能申请吗?