读取文件的建立时间及存取时间
来源:百度文库 编辑:神马文学网 时间:2024/04/29 08:49:42
想要进一步读取文件的相关资讯, 必须先呼叫 API 函数的 OpenFile 取得文件的Handle, 然後再利用 Handle 呼叫 GetFileInformationByHandle 读取文件的相关资讯, 而在读取的文件相关资讯中便含有文件建立、修改、及存取时间, 程式执行过程如下:(假设想读取的文件是\"c:\\autoexec.bat\")
REF 更改文件日期时间
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 Type
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
Type FileTime
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Type 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 Type
Type 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 Type
Declare Function GetTimeZoneInformation Lib \"kernel32\" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long [Page]
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
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 dtCreate As Date ’ 建立时间
Dim dtAccess As Date ’ 存取日期
Dim dtWrite As Date ’ 修改时间
Dim bias As Long
’ 先取得 autoexec.bat 的 File Handle
FileHandle = OpenFile(\"c:\\autoexec.bat\", lpReOpenBuff, OF_READ)
’ 利用 File Handle 读取文件资讯
Call GetFileInformationByHandle(FileHandle, FileInfo)
Call CloseHandle(FileHandle)
’ 读取 Time Zone 资讯, 因为上一步骤的文件时间是「格林威治」时间
Call GetTimeZoneInformation(tZone)
bias = tZone.bias ’ 时间差, 以「分」为单位
Call FileTimeToSystemTime(FileInfo.ftCreationTime, ft) ’ 转换时间资料结构
dtCreate = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + ;
TimeSerial(ft.wHour, ft.wMinute - bias, ft.wSecond)
REF 更改文件日期时间
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 Type
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
Type FileTime
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Type 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 Type
Type 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 Type
Declare Function GetTimeZoneInformation Lib \"kernel32\" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long [Page]
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
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 dtCreate As Date ’ 建立时间
Dim dtAccess As Date ’ 存取日期
Dim dtWrite As Date ’ 修改时间
Dim bias As Long
’ 先取得 autoexec.bat 的 File Handle
FileHandle = OpenFile(\"c:\\autoexec.bat\", lpReOpenBuff, OF_READ)
’ 利用 File Handle 读取文件资讯
Call GetFileInformationByHandle(FileHandle, FileInfo)
Call CloseHandle(FileHandle)
’ 读取 Time Zone 资讯, 因为上一步骤的文件时间是「格林威治」时间
Call GetTimeZoneInformation(tZone)
bias = tZone.bias ’ 时间差, 以「分」为单位
Call FileTimeToSystemTime(FileInfo.ftCreationTime, ft) ’ 转换时间资料结构
dtCreate = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + ;
TimeSerial(ft.wHour, ft.wMinute - bias, ft.wSecond)
读取文件的建立时间及存取时间
用 PHP 读取文件的正确方法
用 PHP 读取文件的正确方法
如何读取损坏光盘内的文件
如何读取损坏光盘内的文件
Mpeg-2的同步及时间恢复
时间码的功能及应用
时间码的功能及应用
时间码的功能及应用
王利芬优米网及拍卖名人时间的商业模式
跑步健身的误区及最佳时间
“眼跳”的真正秘密及对应时间
房产税及土地税的缴纳时间
AVI编码方式及OpenCV读取AVI文件
JR 精品文章 - 利用jdom实现读取数据库生成XML及读取XML文件插入数据库
文件的时间属性也能修改 (包括相片)
1、在记事本中自动记录文件的打开时间
时间。。。
时间)
时间~~~
《时间简史》及续编
时间管理 时间的真谛
MFC文件读取1
我如何从文件读取文本,然后使用我刚读取的文本重命名该文件?