VB怎么获取文件创建时间
Set fs = CreateObject("Scripting.FileSystemObject") '创建FileSystemObject 对象Set f = fs.GetFile("C:\123.exe ") '返回指定路径文件所对应的 File 对象
'File 对象的 DateCreated 属性返回该文件夹的创建日期和时间
'File 对象的 DateLastModified 属性返回最后一次修改该文件的日期和时间
'File 对象的 DateLastAccessed 属性返回最后一次访问该文件的日期和时间
MsgBox "创建时间:" & f.DateCreated & vbCrLf & "修改时间:" & f.DateLastModified & vbCrLf & "访问时间:" & f.DateLastAccessed, vbInformation, f.Name & "属性" --------------------编程问答-------------------- 有什么问题?
还可以用API还获得。
还有vb6的函数FileDateTime,不过它可能返回的是最后修改时间。
--------------------编程问答--------------------
Private Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
试一试这个 --------------------编程问答--------------------
--------------------编程问答--------------------
'Example Name: Determining the Cipher Strength of IE
'------------------------------------------------------------------------------
'
' Form Code
'
'------------------------------------------------------------------------------
Option Explicit
Private Type VS_FIXEDFILEINFO
dwSignature As Long
dwStrucVersion As Long
dwFileVersionMS As Long
dwFileVersionLS As Long
dwProductVersionMS As Long
dwProductVersionLS As Long
dwFileFlagsMask As Long
dwFileFlags As Long
dwFileOS As Long
dwFileType As Long
dwFileSubtype As Long
dwFileDateMS As Long
dwFileDateLS As Long
End Type
Private Declare Function GetSystemDirectory Lib "kernel32" _
Alias "GetSystemDirectoryA" _
(ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Private Declare Function GetFileVersionInfoSize Lib "version.dll" _
Alias "GetFileVersionInfoSizeA" _
(ByVal lptstrFilename As String, _
lpdwHandle As Long) As Long
Private Declare Function GetFileVersionInfo Lib "version.dll" _
Alias "GetFileVersionInfoA" _
(ByVal lptstrFilename As String, _
ByVal dwHandle As Long, _
ByVal dwLen As Long, _
lpData As Any) As Long
Private Declare Function VerQueryValue Lib "version.dll" _
Alias "VerQueryValueA" _
(pBlock As Any, _
ByVal lpSubBlock As String, _
FI As Any, _
nVerSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)
Private Declare Function lstrcpyA Lib "kernel32" _
(ByVal RetVal As String, _
ByVal Ptr As Long) As Long
Private Declare Function lstrlenA Lib "kernel32" _
(ByVal Ptr As Any) As Long
Private Sub Command1_Click()
Label1.Caption = GetIECypherVersion()
End Sub
Private Function GetIECypherVersion() As String
Dim FI As VS_FIXEDFILEINFO
Dim sBuffer() As Byte
Dim nBufferSize As Long
Dim lpBuffer As Long
Dim nVerSize As Long
Dim nUnused As Long
Dim tmpVer As String
Dim sBlock As String
Dim sDLLFile As String
Dim sSysPath As String
sSysPath = GetSystemDir()
If sSysPath > "" Then
'set file that has the encryption level
'info and call to get required size
sDLLFile = sSysPath & "\schannel.dll"
nBufferSize = GetFileVersionInfoSize(sDLLFile, nUnused)
ReDim sBuffer(nBufferSize)
If nBufferSize > 0 Then
'get the version info
Call GetFileVersionInfo(sDLLFile, 0&, nBufferSize, sBuffer(0))
Call VerQueryValue(sBuffer(0), "\", lpBuffer, nVerSize)
Call CopyMemory(FI, ByVal lpBuffer, Len(FI))
If VerQueryValue(sBuffer(0), "\VarFileInfo\Translation", lpBuffer, nVerSize) Then
If nVerSize Then
tmpVer = GetPointerToString(lpBuffer, nVerSize)
tmpVer = Right("0" & Hex(Asc(Mid(tmpVer, 2, 1))), 2) & _
Right("0" & Hex(Asc(Mid(tmpVer, 1, 1))), 2) & _
Right("0" & Hex(Asc(Mid(tmpVer, 4, 1))), 2) & _
Right("0" & Hex(Asc(Mid(tmpVer, 3, 1))), 2)
sBlock = "\StringFileInfo\" & tmpVer & "\FileDescription"
'Get predefined version resources
If VerQueryValue(sBuffer(0), sBlock, lpBuffer, nVerSize) Then
If nVerSize Then
'get the file description string
tmpVer = GetStrFromPtrA(lpBuffer)
'File versions for 40 and 128-bit releases can
'be the same, so we have to do a string search
'to determine the encryption level. If the file
'description contains the line:
'PCT/SSL Security Provider (Export Version), its 40-bit.
'If it contains the line:
'PCT/SSL Security Provider (US and Canada Use Only), its 128-bit.
Select Case InStr(1, tmpVer, "(US and Canada Use Only)", vbTextCompare)
Case 0: GetIECypherVersion = "40-bit normal encryption"
Case Else: GetIECypherVersion = "128-bit strong encryption"
End Select
End If 'If nVerSize
End If 'If VerQueryValue
End If 'If nVerSize
End If 'If VerQueryValue
Else
GetIECypherVersion = "schannel.dll is not in the system folder."
End If 'If nBufferSize
End If 'If sSysPath
End Function
Private Function GetPointerToString(lpString As Long, nBytes As Long) As String
Dim Buffer As String
If nBytes Then
Buffer = Space(nBytes)
CopyMemory ByVal Buffer, ByVal lpString, nBytes
GetPointerToString = Buffer
End If
End Function
Private Function GetStrFromPtrA(ByVal lpszA As Long) As String
GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)
Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)
End Function
Private Function GetSystemDir() As String
Dim nSize As Long
Dim tmp As String
tmp = Space$(256)
nSize = Len(tmp)
Call GetSystemDirectory(tmp, nSize)
GetSystemDir = TrimNull(tmp)
End Function
Private Function TrimNull(item As String)
Dim pos As Integer
'double check that there is a chr$(0) in the string
pos = InStr(item, Chr$(0))
If pos Then
TrimNull = Left$(item, pos - 1)
Else: TrimNull = item
End If
End Function
lz不是已经获得文件的创建日期和时间了吗
--------------------编程问答-------------------- 这么小的程序员啊
补充:VB , 基础类