请问读取文件的时间戳的API是什么?

yagumo 2003-08-30 05:25:46
文件有本地文件与远程文件之分,远程文件是指FTP服务器上的文件.
...全文
124 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gelim 2003-09-04
  • 打赏
  • 举报
回复
使用ftp命令!







__________________________________________
给分我长角
yagumo 2003-09-02
  • 打赏
  • 举报
回复
没人知道吗?自己顶一下.
yagumo 2003-09-01
  • 打赏
  • 举报
回复
谢谢朋友们的回答,不过我想此题的重点和难点是在如何读取FTP服务器上文件时间上.我想做一个东西自动比较本地文件和FTP上文件的新旧,如何FTP的新,则下载更新本地文件.我试过FileDateTime(),这个只能读本地文件,远程FTP上的似乎不行.四楼的兄弟能否给个例子?
lihonggen0 2003-09-01
  • 打赏
  • 举报
回复

读取文件的建立时间及存取时间


  想要进一步读取文件的相关资讯, 必须先呼叫 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
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)
Call FileTimeToSystemTime(FileInfo.ftLastAccessTime, ft)
dtAccess = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + ;
TimeSerial(ft.wHour, ft.wMinute - bias,ft.wSecond)
Call FileTimeToSystemTime(FileInfo.ftLastWriteTime, ft)
dtWrite = DateSerial(ft.wYear, ft.wMonth, ft.wDay) +
TimeSerial(ft.wHour, ft.wMinute - bias,ft.wSecond)

'执行以上程式所得到的 dtCreate、dtWrite、及 dtAccess 变数, 即分别为文件
'建立、修改、及存取时间。



 


blueice2002 2003-09-01
  • 打赏
  • 举报
回复
Public Declare Function GetFileTime Lib "kernel32" Alias "GetFileTime" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
xwzxwz 2003-08-31
  • 打赏
  • 举报
回复
一样
yagumo 2003-08-30
  • 打赏
  • 举报
回复
但是远程FTP服务器上的文件呢,有什么办法吗?
wumy_ld 2003-08-30
  • 打赏
  • 举报
回复
vb自带的函数FileDateTime,不需要api。

FileDateTime 函数
返回一个 Variant (Date),此为一个文件被创建或最后修改后的日期和时间。

语法

FileDateTime(pathname)

必要的 pathname 参数是用来指定一个文件名的字符串表达式。pathname 可以包含目录或文件夹、以及驱动器。

1,486

社区成员

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

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