从文件中获取扩展属性

我试图从脚本运行的文件夹中的视频文件获取扩展文件属性,并将结果输出到文本文件。从文件中获取扩展属性

这是我到目前为止的代码:

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)。我如何指定与文件类型数组匹配的所有文件?我试过fl.name和fd.files。我不知道还有什么要尝试。

我双击在Windows 7

脚本从Windows资源管理VBS文件运行脚本,没有错误,运行和返回的文件名,但不返回扩展属性。任何帮助将不胜感激。

回答:

下面的代码能够获取像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

以上是 从文件中获取扩展属性 的全部内容, 来源链接: utcz.com/qa/258425.html

回到顶部