Option Explicit
Private Sub Command1_Click()
Dim MyFileSystem As New FileSystemObject
Dim MyFile As File
Set MyFile = MyFileSystem.GetFile("C:\ssk.txt") '对应的文件标识符
Print "文件创建时间:"MyFile.DateCreated'文件创建时间
Print "文件访问时间:"MyFile.DateLastAccessed '文件访问时间
Print "文件修改时间:"MyFile.DateLastModified '文件修改时间
End Sub
Private Sub Command1_Click()Text1.Text = FileDateTime("d:\shuju\db.mdb")
'FileDateTime函数是获取一个文件创建或修改的日期和时间的函数
'这个日期和时间是根据你的系统设置的日期和时间的格式确定的
End Sub Private Sub Command2_Click()
End
End Sub Private Sub Form_Load()
Text1.Text = ""
End Sub
用FtpFindFirstFile,InternetFindNextFile 这两个函数
FtpFindFirstFile 返回文件信息。放在 WIN32_FIND_DATA 结构中
InternetFindNextFile 调用 FtpFindFirstFile()后在目录中连续查找
当找到FTP服务器上的一个文件时,可获得该文件的最后一次修改时间
函数的声明是:
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String,lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long,ByVal dwContent As Long) As LongPrivate Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
还需定义一个数据类型:WIN32_FIND_DATA,用于保存相关路径下的文件的信息。类型结构如下:
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
ftLastWriteTime就是最后的修改时间
例:
FtpFindFirstFile(FTP连接句柄,需要知道日期的文件名,WIN32_FIND_DATA格式的变量,2,0)
API函数FileTimeToSystemTime可以将FILETIME转换为系统时间结构SYSTEMTIME
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)