非常菜,SetFileTime函数中句柄的获得什么不会,想求助例子,非常急,谢谢!
目的就是只要能够把 C:\abc.xls的创建时间修改为我制定的时间就可以了,谢谢!只要例句即可,10分送上

解决方案 »

  1.   

    VB6.0 里如何修改文件的日期/时间? 
    使用SetFileTime例子:
    http://www.programfan.com/club/showpost.asp?id=50472&t=o
      

  2.   

    回楼上的,那个太复杂了,有没有简单明了一点的例子?谢谢直接使用setfiletime函数
      

  3.   

    Option ExplicitPrivate Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
    End TypePrivate 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 TypePrivate Const GENERIC_WRITE = &H40000000
    Private Const OPEN_EXISTING = 3
    Private Const FILE_SHARE_READ = &H1
    Private Const FILE_SHARE_WRITE = &H2Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
    Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) 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 CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Sub Form_Load()
        Dim m_Date As Date, lngHandle As Long, strFileName As String
        
        Dim udtFileTime As FILETIME
        Dim udtLocalTime As FILETIME
        Dim udtSystemTime As SYSTEMTIME
        
        m_Date = CDate("2008-8-8 20:00:00")
        
        strFileName = "C:\A.txt" '这行为文件地址,最重要的。楼主只要这里就可以
        
        udtSystemTime.wYear = Year(m_Date)
        udtSystemTime.wMonth = Month(m_Date)
        udtSystemTime.wDay = Day(m_Date)
        udtSystemTime.wDayOfWeek = Weekday(m_Date) - 1
        udtSystemTime.wHour = Hour(m_Date)
        udtSystemTime.wSecond = Second(m_Date)
        udtSystemTime.wMilliseconds = 0
        ' convert system time to local time
        SystemTimeToFileTime udtSystemTime, udtLocalTime
        ' convert local time to GMT
        LocalFileTimeToFileTime udtLocalTime, udtFileTime
        ' open the file to get the filehandle
        lngHandle = CreateFile(strFileName, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
        ' change date/time property of the file
        SetFileTime lngHandle, udtFileTime, udtFileTime, udtFileTime
        ' close the handle
        CloseHandle lngHandle
        'MsgBox "The date of the file '" & strFileName & "' has been changed to" & Str$(m_Date), vbInformation + vbOKOnly, App.Title
        MsgBox "文件“" & strFileName & "”的“创建时间”与“修改时间”已被设置为" & Format(m_Date, "“yyyy年m月d日, hh:mm:ss”"), vbInformation + vbOKOnly, App.Title
    End Sub
      

  4.   

    strFileName = "C:\A.txt" '这行为文件地址,最重要的。楼主只要改这里就可以
      

  5.   

     SystemTimeToFileTime udtSystemTime, udtLocalTime   这句话报错说
    "编译错误,ByRef参数类型不符"
      

  6.   

    Email:[email protected]
    楼主,你要的程序已发。给分吧.呵呵
      

  7.   

    hello,你好,非常感谢。
    情况是这样的,我需要自动批量修改文件的时间,修改的条件,判断的规则我都知道了,唯一不知道的就是如何把时间修改,因此我需要的是一段可行的程序代码,从而嵌入我自己的程序段中,达到目的,因此我希望得到你可行的程序的代码,只要能够完成文件创建时间修改这个目的的代码即可,不胜感激!