获取已知文件信息

wjf7688 2001-06-22 10:44:00
如何获取一已知目录下已知文件的类型和时间???
...全文
117 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
eaglezhao 2001-06-24
  • 打赏
  • 举报
回复
使用Api函数,将我的代码拷贝过去可以直接用,如果你有耐心,看一下就会明白。
1、首先是调用函数必须的结构声明和函数声明
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
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

2、下面的函数可以直接调用,参数意义为:文件名、创建时间、存取时间和修改时间

Private Sub apiFileDateTime(ByVal PathName As String, dtCreate As Date, dtAccess As Date, dtWrite As Date)

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 bias As Long

FileHandle = OpenFile(PathName, lpReOpenBuff, OF_READ)

GetFileInformationByHandle FileHandle, FileInfo
CloseHandle FileHandle

GetTimeZoneInformation tZone
bias = tZone.bias

FileTimeToSystemTime FileInfo.ftCreationTime, ft
dtCreate = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + _
TimeSerial(ft.wHour, ft.wMinute - bias, ft.wSecond)

FileTimeToSystemTime FileInfo.ftLastAccessTime, ft
dtAccess = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + _
TimeSerial(ft.wHour, ft.wMinute - bias, ft.wSecond)

FileTimeToSystemTime FileInfo.ftLastWriteTime, ft
dtWrite = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + _
TimeSerial(ft.wHour, ft.wMinute - bias, ft.wSecond)

End Sub
jisheng 2001-06-24
  • 打赏
  • 举报
回复
getfiletime
setfiletime
ltpao 2001-06-24
  • 打赏
  • 举报
回复
用Getversioninfo
enmity 2001-06-24
  • 打赏
  • 举报
回复
filedatetime()
pp616 2001-06-22
  • 打赏
  • 举报
回复
用fso去看看书。很简单的。
hzc1 2001-06-22
  • 打赏
  • 举报
回复
需要用到API函数FindFirstFile、FindClose。

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧