Option Explicit
Function GetFileDuration(FolderSpec As String) As Date
'请在VBE/工具/引用中勾选对于MICROSOFT SHELL CONTROLS AND AUTOMATION
Dim SHL As New Shell32.Shell
Dim SHFD As Shell32.Folder
Dim F As Object
Set SHFD = SHL.NameSpace(FolderSpec)
For Each F In SHFD.Items
If InStr(1, F.Name, ".WMV", vbTextCompare) Then
GetFileDuration = GetFileDuration + SHFD.GetDetailsOf(F, 21)
End If
Next
End Function
Sub Example()
MsgBox GetFileDuration("F:\Pictures\Microsoft")
End Sub
说明:
shell32对象非常有用,利用它几乎可以访问文件的所有信息。利用GetDetailsOf可以获取文件(包括视频文件)的属性信息。试一试吧,上面是一个获取视频(WMV)的VBA程序。