我正在尝试从运行脚本的文件夹中的视频文件中获取扩展文件属性,并将结果输出到文本文件。
这是我到目前为止的代码:
Dim ls, fsObj, fd, fs, fl, sfs, sf, tf
' specify the file extensions to list
dim fileTypes
fileTypes = Array("mp4","mkv","avi")
On Error Resume Next
ls = ""
Set fsObj = CreateObject("Scripting.FileSystemObject")
Set fd = fsObj.GetFolder(".")
Set objFolder = objShell.NameSpace(fsObj)
set fs = fd.Files
For Each fileName in objFolder.Items
set objFolderItem = objFolder.ParseName(fileName)
size = objFolder.GetDetailsOf(objFolderItem, 1)
length = objFolder.GetDetailsOf(objFolderItem, 27)
height = objFolder.GetDetailsOf(objFolderItem, 283)
width = objFolder.GetDetailsOf(objFolderItem, 285)
Next
' list subfolders
set sfs = fd.SubFolders
For Each sf in sfs
ls = ls & sf.name & vbCrLf & chr(10)
Next
For Each fl in fs
' check whether the extension matches
if arrayContains(fileTypes, fsObj.GetExtensionName(fl.name))then
ls = ls & fl.name & vbtab & length & vbCrLf & chr(10)
end if
Next
Set tf = fsObj.OpenTextFile("index.txt", 2, True, False)
tf.Writeline ls
tf.Close
Set fsObj = Nothing
function arrayContains (arr, val)
dim found
found = false
for i = 0 to ubound(arr)
if arr(i) = val then
found = true
exit for
end if
next
arrayContains = found
end function
我试图获取文件名和长度,一旦我可以得到它我可以添加其他。
据我所知,我需要指定objFolder.ParseName(fileName)。如何指定与filetypes数组匹配的所有文件?我试过fl.name和fd.files。我不知道还有什么可以尝试。
我通过在Windows 7中双击Windows资源管理器中的vbs文件来运行脚本。
脚本运行时没有错误并返回文件名,但不返回扩展属性。任何帮助将不胜感激。
答案 0 :(得分:3)
以下代码可以获取mp4文件的名称,大小,长度,帧高和帧宽等详细信息。对于格式为flv,avi,mkv的文件,它只能提取其名称和大小。对于这些文件,即使右键单击它们,选择属性并转到“详细信息”选项卡,也不会看到有关其长度,高度和宽度的信息。但是对于mp4,你可以看到所有这些细节。
试试这段代码:
Set fso = CreateObject("scripting.filesystemobject")
Set obs = CreateObject("shell.application")
Set fol = fso.GetFolder(".")
Set spl = obs.NameSpace(fol.Path)
Set files = fol.Files
filePath = fol.path&"\Info.txt"
set objFile = fso.openTextFile(filePath,2,true,true)
arr = Array("mp4", "mkv", "avi", "flv")
For Each file In files
ext = fso.GetExtensionName(file.Name)
For Each ex In arr
If StrComp(ext,ex,1)=0 Then
objFile.writeline "NAME: "&spl.GetDetailsOf(spl.ParseName(file.Name),0)&vbcrlf&_
"SIZE: "&spl.GetDetailsOf(spl.ParseName(file.Name),1)&vbcrlf&_
"LENGTH: "&spl.GetDetailsOf(spl.ParseName(file.Name),27)&vbcrlf&_
"FRAME HEIGHT: "&spl.GetDetailsOf(spl.ParseName(file.Name),283)&vbcrlf&_
"FRAME WIDTH: "&spl.GetDetailsOf(spl.ParseName(file.Name),285)&vbcrlf&string(50,"==")
Exit For
End If
Next
Next
objFile.Close
set objFile = Nothing
set files = nothing
set spl = nothing
set fol = nothing
set obs = nothing
set fso = nothing