• 修改文件创建时间


     1 Option Explicit
     2 
     3 Public Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
     4 Public Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SystemTime, lpFileTime As FILETIME) As Long
     5 Public Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As LongAs Long
     6 Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As LongAs Long
     7 Public Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
     8 Public Const OF_EXIST = &H4000
     9 Public Const OFS_MAXPATHNAME = 128
    10 Public Const OF_READWRITE = &H2
    11 
    12 Public Type OFSTRUCT
    13     cBytes   As Byte
    14     fFixedDisk   As Byte
    15     nErrCode   As Integer
    16     Reserved1   As Integer
    17     Reserved2   As Integer
    18     szPathName(OFS_MAXPATHNAME)   As Byte
    19 End Type
    20 Public Type FILETIME
    21     dwLowDateTime   As Long
    22     dwHighDateTime   As Long
    23 End Type
    24 
    25 Public Type SystemTime
    26     wYear   As Integer
    27     wMonth   As Integer
    28     wDayOfWeek   As Integer
    29     wDay   As Integer
    30     wHour   As Integer
    31     wMinute   As Integer
    32     wSecond   As Integer
    33     wMilliseconds   As Integer
    34 End Type
    35 
    36 Public Sub ModiFileTime(sFile As String, 日期 As SystemTime)
    37     Dim Rev     As Long
    38     Dim hFile     As Long
    39     Dim fTime     As FILETIME
    40     Dim fLTime     As FILETIME
    41     Dim fStruct     As OFSTRUCT
    42 
    43     Rev = SystemTimeToFileTime(日期, fLTime)
    44     Rev = LocalFileTimeToFileTime(fLTime, fTime)
    45     hFile = OpenFile(sFile, fStruct, OF_READWRITE)
    46     Rev = SetFileTime(hFile, fTime, fTime, fTime)
    47     Rev = CloseHandle(hFile)
    48 End Sub
    49 
    50 '使用方法
    51 Private Sub Form_Load()
    52     Dim 日期     As SystemTime
    53     With 日期       '2008/04/14     20:00:00
    54             .wYear = 2008
    55             .wMonth = 4
    56             .wDay = 14
    57             .wHour = 20
    58             .wMinute = 0
    59             .wSecond = 0
    60     End With
    61     ModiFileTime "C:\1.ico", 日期
    62 End Sub
    63 
  • 相关阅读:
    javascript中的几点说明
    repeater 绑定数组
    SQL语句之按in排序
    固定VS2005端口号
    关于asp.net中动态获取LinkButton的Text值的问题
    ASP.NET 2.0中直接得到本页面生成的HTML代码
    实现数据库的备份与还原的功能
    使用ASP.NET 2.0提供的WebResource管理内嵌资源(c#)
    [IIS]由于无法创建应用程序域,因此未能执行请求解决方案汇总
    VS2005中引用Microsoft Office COM组件
  • 原文地址:https://www.cnblogs.com/xxaxx/p/1635323.html
Copyright © 2020-2023  润新知