我在NETWARE上有一个文件,如果被修改,就用SHELL执行 Xcopy 拷贝到本地来,可是我用GETFILETIME却无法得到正确的文件被修改时间,文件已经被改过了,时间却没改,100分奉上好心人。

解决方案 »

  1.   

    Dim g As Object 
         
         Dim f As Variant 
         
         Set g = CreateObject("Scripting.FileSystemObject") 
         
         Set f = g.GetFile("c:\Autoexec.bat") 
         
         
         MsgBox vbLf & "创建时间:" & f.DateCreated & _ 
         vbLf & "修改时间:" & f.DateLastModified & _ 
         vbLf & "访问时间:" & f.DateLastAccessed
      

  2.   

    Public Const OF_READWRITE = &H2
    Public Const OFS_MAXPATHNAME = 128
    Public Const OF_READ = &H0
    Type OFSTRUCT
        cBytes As Byte
        fFixedDisk As Byte
        nErrCode As Integer
        Reserved1 As Integer
        Reserved2 As Integer
        szPathName(OFS_MAXPATHNAME) As Byte
    End TypeType 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 TypeType FileTime
         dwLowDateTime As Long
         dwHighDateTime As Long
    End TypeType BY_HANDLE_FILE_INFORMATION
         dwFileAttributes As Long
         ftCreationTime As FileTime
         ftLastAccessTime As FileTime
         ftLastWriteTime As FileTime
         dwVolumeSerialNumber As Long
         nFileSizeHigh As Long
         nFileSizeLow As Long
         nNumberOfLinks As Long
         nFileIndexHigh As Long
         nFileIndexLow As Long
    End TypeType TIME_ZONE_INFORMATION
         bias As Long
         StandardName(32) As Integer
         StandardDate As SYSTEMTIME
         StandardBias As Long
         DaylightName(32) As Integer
         DaylightDate As SYSTEMTIME
         DaylightBias As Long
    End TypeDeclare Function GetTimeZoneInformation Lib "KERNEL32" _
        (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    Declare Function OpenFile Lib "KERNEL32" (ByVal lpFileName As String, _
        lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
    Declare Function GetFileInformationByHandle Lib "KERNEL32" (ByVal hFile As _
        Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
    Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
    Declare Function FileTimeToSystemTime Lib "KERNEL32" (lpFileTime As _
        FileTime, lpSystemTime As SYSTEMTIME) As Long
    Declare Function SetFileTime Lib "KERNEL32" (ByVal hFile As Long, lpCreationTime As Any, lpLastAccessTime As Any, lpLastWriteTime As Any) As Long
    Declare Function SystemTimeToFileTime Lib "KERNEL32" (lpSystemTime As SYSTEMTIME, lpFileTime As FileTime) As Long
    Declare Sub GetSystemTime Lib "KERNEL32" (lpSystemTime As SYSTEMTIME)
    Declare Sub GetLocalTime Lib "KERNEL32" (lpSystemTime As SYSTEMTIME)Public Function GetWriteDate(sFile As String) As Date
        Dim FileHandle As Long
        Dim FileInfo As BY_HANDLE_FILE_INFORMATION
        Dim lpReOpenBuff As OFSTRUCT, ft As SYSTEMTIME
        Dim tZone As TIME_ZONE_INFORMATION
        
        Dim dtWrite As Date
        Dim bias As Long
        
        FileHandle = OpenFile(sFile, lpReOpenBuff, OF_READ)
        Call GetFileInformationByHandle(FileHandle, FileInfo)
        Call CloseHandle(FileHandle)
        Call GetTimeZoneInformation(tZone)
        bias = tZone.bias
        Call FileTimeToSystemTime(FileInfo.ftLastWriteTime, ft)
        dtWrite = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + _
               TimeSerial(ft.wHour, ft.wMinute - bias, ft.wSecond)
        GetWriteDate = dtWrite
        Call CloseHandle(FileHandle)
    End Function用法:msgbox GetWriteDate("c:\test.exe")
      

  3.   

    to :happy_sea(开心海)给一个完整的好收藏啦-----------
    www.vicmiao.com
    努力就有美好时光!