如何使用VBScript读取mp4文件的属性

时间:2014-07-31 04:21:22

标签: vbscript mp4

我试图使用VBScript创建我的电影库数据库,但我无法弄清楚如何获取mp4文件的属性。为了类似的目的,我在不同的question中使用了此代码。这是我到目前为止的代码。

Option Explicit
Dim objFSO,objf,objfolder, objFile, strFileProperties, strFiles,OBJFLD,objfile2
dim objf1,objfile1,objtextfile,strfolderproperties,objsubfld,objfl,objfl1,strfileproperties2

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objf= objFSO.Getfolder("E:\Share Drive\Chris\Movies")
set OBJfl=objf.files
for each objfl1 in OBJfl
  'display properties of the files of the main folder   
  strFileProperties2 = strFileProperties2 & "Title: " & objfl1.Name & VbCrLf
  strFileProperties2 = strFileProperties2 & "Size: " & objFl1.Size & " bytes" & VbCrLf
  strFileProperties2 = strFileProperties2 & "Type: " & objFl1.Type & VbCrLf & vbcrlf
next

set objf1=objfso.getfolder("C:\")

set objfile1=objfso.getfile( "C:\database.txt")

set objf1=nothing
set objfile1=nothing

set objtextfile=objfso.opentextfile("C:\database.txt",8,true)

objtextfile.writeline(strfileproperties)
objtextfile.writeline(strfileproperties2)
objtextfile.close

set objf1=objfso.getfolder("C:\")

set objfile1=objfso.getfile( "C:\database.txt")

set objf1=nothing
set objfile1=nothing

set objsubfld=objfso.opentextfile("C:\database.txt",8,true)
objsubfld.writeline(strfolderproperties)
objsubfld.close

我喜欢的其他属性是框架宽度,框架高度和长度。我已经尝试了objMp4File.Length,但我收到一条错误消息,说它没有定义。我是VBScript的新手,所以我可能会采用错误的方式。

2 个答案:

答案 0 :(得分:0)

试一试

Option Explicit

Dim shellApplication, folderNamespace

    Set shellApplication = CreateObject("Shell.Application")
    Set folderNamespace  = shellApplication.Namespace("E:\Share Drive\Chris\Movies")

Dim headers, i, aHeaders(290)
    For i = 0 to 289
        aHeaders(i) = folderNamespace.GetDetailsOf(folderNamespace.Items, i)
    Next


Dim fileName    
    For Each fileName in folderNamespace.Items
        If LCase(Right(fileName,4))=".mp4" Then 
            For i = 0 to 289
                Wscript.Echo i & vbtab & aHeaders(i) & ": " & folderNamespace.GetDetailsOf(fileName, i)
            Next
            WScript.Echo "-------------------------------------------------------"
        End If
    Next

每种文件可用的属性集可以并且会有所不同。

答案 1 :(得分:0)

这取决于您的操作系统,对于Windows 7,这将有效,请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/bb787870%28v=vs.85%29.aspx;

fname = objFolder.GetDetailsOf(objFolderItem, 155)
size = objFolder.GetDetailsOf(objFolderItem, 1)
ftype = objFolder.GetDetailsOf(objFolderItem, 2)
length = objFolder.GetDetailsOf(objFolderItem, 27)
frameheight = objFolder.GetDetailsOf(objFolderItem, 283)
framewidth = objFolder.GetDetailsOf(objFolderItem, 285)