zoukankan      html  css  js  c++  java
  • 修改文件创建时间

     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 
  • 相关阅读:
    算法-heapq模块优先队列
    用find命令删除某目录下及所有子目录中某类型的特定文件
    OpenStack虚拟机virtaulinterfance 网络设备在libvirt的代码梳理
    cinderclient命令行源码解析
    python 多个装饰器的调用顺序分析
    wsgi的environ变量
    Cirros镜像
    写入多个变量到配置文件【linux】
    SecureCRT 私钥登录ec2 报:A protocol error occurred.Too many authentication failures for ec2-user 解决
    S3上备份的json文件转存成parquet文件
  • 原文地址:https://www.cnblogs.com/xxaxx/p/1635323.html
Copyright © 2011-2022 走看看