修改文件时间
2007-07-27 15:44
197 查看
=====================================================================================
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
【说明】
根据一个FILETIME结构的内容,载入一个SYSTEMTIME结构
【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError
【参数表】
lpSystemTime - SYSTEMTIME,包含了系统时间信息的一个结构
lpFileTime - FILETIME,用于装载文件时间的一个结构
=====================================================================================
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
【说明】
将本时区的文件时间转换成格林威治时间的文件时间。
=====================================================================================
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
【说明】
【参数表】
lpFileName - String,欲打开文件的名字
lpReOpenBuff - OFSTRUCT,该结构填充的数据包括与文件和操作结果有关的信息
wStyle - Long,参考表OpenFile-1(OpenFile函数的标志常数表)总结的标志常数的组合,它决定了要采取的操作方式
表OpenFile-1(OpenFile函数的标志常数表)
wStyle常数
=====================================================================================
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
【说明】
设置文件创建时间、访问时间及修改时间
【返回值】
Long,非零表示成功,零表示失败。
【参数表】
hFile - Long,文件句柄
lpCreationTime - FILETIME,文件的创建时间
lpLastAccessTime - FILETIME,文件的访问时间
lpLastWriteTime - FILETIME,文件的修改时间
=====================================================================================
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
【说明】
关闭一个内核对象。其中包括文件、文件映射、进程、线程、安全和同步对象等。涉及文件处理时,这个函数通常与vb的close命令相似。应尽可能的使用close,因为它支持vb的差错控制。注意这个函数使用的文件句柄与vb的文件编号是完全不同的
【返回值】
Long,非零表示成功,零表示失败。
【备注】
除非对内核对象的所有引用都已关闭,否则该对象不会实际删除
【参数表】
hObject - Long,欲关闭的一个对象的句柄
=====================================================================================
Option Explicit
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Const OF_READWRITE = &H2
Private Const OFS_MAXPATHNAME = 128
Private 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 Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
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 Sub Form_Load()
ChangeFileTime "c:/123.txt"
Unload Me
End Sub
Private Sub ChangeFileTime(StrFile As String)
Dim CreationSysTime As SYSTEMTIME
Dim AccessSysTime As SYSTEMTIME
Dim ChangeSysTime As SYSTEMTIME
Dim LocalCreationFileTime As FILETIME
Dim LocalAccessFileTime As FILETIME
Dim LocalChangeFiletime As FILETIME
Dim CreationFileTime As FILETIME
Dim AccessFileTime As FILETIME
Dim ChangeFileTime As FILETIME
Dim hFile As Long
Dim fStruct As OFSTRUCT
With CreationSysTime '2005年11月20日,12:10:20
.wYear = 2005
.wMonth = 11
.wDay = 20
.wHour = 12
.wMinute = 10
.wSecond = 20
End With
With AccessSysTime '2006年10月7日,16:42:13
.wYear = 2006
.wMonth = 10
.wDay = 7
.wHour = 16
.wMinute = 42
.wSecond = 13
End With
With ChangeSysTime '2005年4月4日, 13:41:30
.wYear = 2005
.wMonth = 4
.wDay = 4
.wHour = 13
.wMinute = 41
.wSecond = 30
End With
SystemTimeToFileTime CreationSysTime, LocalCreationFileTime
LocalFileTimeToFileTime LocalCreationFileTime, CreationFileTime
SystemTimeToFileTime AccessSysTime, LocalAccessFileTime
LocalFileTimeToFileTime LocalAccessFileTime, AccessFileTime
SystemTimeToFileTime ChangeSysTime, LocalChangeFiletime
LocalFileTimeToFileTime LocalChangeFiletime, ChangeFileTime
hFile = OpenFile(StrFile, fStruct, OF_READWRITE)
SetFileTime hFile, CreationFileTime, AccessFileTime, ChangeFileTime
CloseHandle hFile
End Sub
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
【说明】
根据一个FILETIME结构的内容,载入一个SYSTEMTIME结构
【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError
【参数表】
lpSystemTime - SYSTEMTIME,包含了系统时间信息的一个结构
lpFileTime - FILETIME,用于装载文件时间的一个结构
=====================================================================================
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
【说明】
将本时区的文件时间转换成格林威治时间的文件时间。
=====================================================================================
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
【说明】
【参数表】
lpFileName - String,欲打开文件的名字
lpReOpenBuff - OFSTRUCT,该结构填充的数据包括与文件和操作结果有关的信息
wStyle - Long,参考表OpenFile-1(OpenFile函数的标志常数表)总结的标志常数的组合,它决定了要采取的操作方式
表OpenFile-1(OpenFile函数的标志常数表)
wStyle常数
=====================================================================================
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
【说明】
设置文件创建时间、访问时间及修改时间
【返回值】
Long,非零表示成功,零表示失败。
【参数表】
hFile - Long,文件句柄
lpCreationTime - FILETIME,文件的创建时间
lpLastAccessTime - FILETIME,文件的访问时间
lpLastWriteTime - FILETIME,文件的修改时间
=====================================================================================
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
【说明】
关闭一个内核对象。其中包括文件、文件映射、进程、线程、安全和同步对象等。涉及文件处理时,这个函数通常与vb的close命令相似。应尽可能的使用close,因为它支持vb的差错控制。注意这个函数使用的文件句柄与vb的文件编号是完全不同的
【返回值】
Long,非零表示成功,零表示失败。
【备注】
除非对内核对象的所有引用都已关闭,否则该对象不会实际删除
【参数表】
hObject - Long,欲关闭的一个对象的句柄
=====================================================================================
Option Explicit
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Const OF_READWRITE = &H2
Private Const OFS_MAXPATHNAME = 128
Private 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 Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
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 Sub Form_Load()
ChangeFileTime "c:/123.txt"
Unload Me
End Sub
Private Sub ChangeFileTime(StrFile As String)
Dim CreationSysTime As SYSTEMTIME
Dim AccessSysTime As SYSTEMTIME
Dim ChangeSysTime As SYSTEMTIME
Dim LocalCreationFileTime As FILETIME
Dim LocalAccessFileTime As FILETIME
Dim LocalChangeFiletime As FILETIME
Dim CreationFileTime As FILETIME
Dim AccessFileTime As FILETIME
Dim ChangeFileTime As FILETIME
Dim hFile As Long
Dim fStruct As OFSTRUCT
With CreationSysTime '2005年11月20日,12:10:20
.wYear = 2005
.wMonth = 11
.wDay = 20
.wHour = 12
.wMinute = 10
.wSecond = 20
End With
With AccessSysTime '2006年10月7日,16:42:13
.wYear = 2006
.wMonth = 10
.wDay = 7
.wHour = 16
.wMinute = 42
.wSecond = 13
End With
With ChangeSysTime '2005年4月4日, 13:41:30
.wYear = 2005
.wMonth = 4
.wDay = 4
.wHour = 13
.wMinute = 41
.wSecond = 30
End With
SystemTimeToFileTime CreationSysTime, LocalCreationFileTime
LocalFileTimeToFileTime LocalCreationFileTime, CreationFileTime
SystemTimeToFileTime AccessSysTime, LocalAccessFileTime
LocalFileTimeToFileTime LocalAccessFileTime, AccessFileTime
SystemTimeToFileTime ChangeSysTime, LocalChangeFiletime
LocalFileTimeToFileTime LocalChangeFiletime, ChangeFileTime
hFile = OpenFile(StrFile, fStruct, OF_READWRITE)
SetFileTime hFile, CreationFileTime, AccessFileTime, ChangeFileTime
CloseHandle hFile
End Sub
相关文章推荐
- linux下删除修改时间为某天之前的文件
- php filemtime -- 取得文件修改时间
- 用 C# 轻松读取、改变文件的创建、修改、访问时间
- VC实现修改文件创建、访问、修改时间属性(转载)
- java实现根据文件最后的修改时间排序
- 排序文件文件按文件名、修改时间、文件大小进行排序
- 时间戳 和 make: *** 警告:文件 “ManyDialog.pro”的修改时间在将来9.1e+04
- [Windows]_[初级]_[修改文件的创建时间-修改时间-访问时间]
- linux 下查看文件修改时间,访问时间,状态改变时间
- VB 检测网络文件的修改时间
- 如何获知文件最后的修改日期和时间?
- pb9获取文件创建时间、最后修改时间及设置最后修改时间的方法
- Linux系统下ACM时间查看修改和文件目录权限处理
- 安卓判断文件的最后修改时间
- C#实现对指定文件夹中文件按修改时间排序
- 根据文件修改时间批量移动到指定目录
- Linux下用C语言显示文件夹下所有文件的名称、大小、最后修改时间
- linux中touch命令参数修改文件的时间戳
- C# 获取文件的修改时间、访问时间、创建时间
- Linux系统下查看某文件修改的时间戳