gpt4 book ai didi

vbscript - 从文件中获取扩展属性

转载 作者:行者123 更新时间:2023-12-01 01:47:26 25 4
gpt4 key购买 nike

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

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

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 文件来运行脚本。

该脚本运行没有错误并返回文件名,但不返回扩展属性。任何帮助将不胜感激。

最佳答案

以下代码能够获取 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

关于vbscript - 从文件中获取扩展属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47612821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com