使用VBS获取文档属性 [英] get document properties using VBS
问题描述
我有一个包含几个文件的文件夹. 我想为每个文件获取分配给该文件的所有属性及其值的列表.
I have a folder containing few files. I would like to get, for each file, a list of all the properties assigned to this file and their values.
我已经写了以下几行,但是我无法确定在占位符中使用的正确方法MethodIamLookingFor1(获取分配的属性列表),MethodIamLookingFor2(获取属性名称)和MethodIamLookingFor3(获取属性值):
I have written these few lines but I am not able to identify the right methods to use in the placeholders MethodIamLookingFor1 (to get list of properties assigned), MethodIamLookingFor2 (to get property name) and MethodIamLookingFor3 (to get property value):
Dim sFolder
sFolder = "C:\Batch_DEV\to"
Dim objFSO, objDir, listObjFiles, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDir = objFSO.GetFolder(sFolder)
Set listObjFiles = objDir.Files
For Each objFile In listObjFiles
Wscript.Echo objFile.name & ": "
listProperties = objFile.MethodIamLookingFor1
For Each objFileProperty In listProperties
Wscript.Echo "property name is: " & objFileProperty.MethodIamLookingFor2
Wscript.Echo "property value is: " & objFileProperty.MethodIamLookingFor3
Next
Next
能请你帮忙吗? 谢谢!
Could you please help? thanks!
推荐答案
忽略VBA关键字,因为它可以轻松转换为VBScript.见下文.
ignore the VBA keyword as it can be converted to VBScript with little effort. See below.
Dim fso
Dim txtStream
Dim sFile
Dim oShell
Set oShell = CreateObject("Shell.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oDir
Set oDir = oShell.Namespace(pathToFolder)
Set txtStream = fso.OpenTextFile(pathToTextFile, 2, True, -2)
For Each sFile In oDir.Items
For i = 0 To 40
txtStream.WriteLine i & " : " & oDir.GetDetailsOf(oDir.Items, i) & " : " & oDir.GetDetailsOf(sFile, i)
Next
Next
这篇关于使用VBS获取文档属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!