我有一个包含少量文件的文件夹。 我想为每个文件获取分配给该文件的所有属性及其值的列表。
我写了这几行,但是我无法确定在占位符MethodIamLookingFor1(获取属性列表),MethodIamLookingFor2(获取属性名称)和MethodIamLookingFor3(获取属性值)中使用的正确方法:
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
你可以帮忙吗?
谢谢!
答案 0 :(得分:2)
来自Using VBA to get extended file attributes的代码
忽略VBA关键字,因为它可以很轻松地转换为VBScript。见下文。
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
答案 1 :(得分:1)
我不记得VBScript有一个可用于枚举文件属性的属性。 VB6包含允许的FileInfo对象。
使用VBScript,您需要指定所需的每个属性。文件属性列在MSDN。
上答案 2 :(得分:1)
谢谢,我使用了您指示的GetDetailsOf指令并调整了我的代码以使用https://technet.microsoft.com/en-us/library/ee176615.aspx输入
test.txt:
property name is: Nome
property value is: test.txt
property name is: Dimensione
property value is: 351 byte
property name is: Tipo elemento
property value is: File TXT
property name is: Ultima modifica
property value is: 23/12/2015 14:34
property name is: Data creazione
property value is: 29/12/2015 09:30
property name is: Data ultimo accesso
property value is: 29/12/2015 09:30 word
sample.docx:
property name is: Nome
property value is: word sample.docx
property name is: Dimensione
property value is: 11,1 KB
property name is: Tipo elemento
property value is: Documento di Microsoft Word
property name is: Ultima modifica
property value is: 10/12/2015 16:24
property name is: Data creazione
property value is: 29/12/2015 09:31
property name is: Data ultimo accesso
property value is: 29/12/2015 09:31
所以最后的方法是:
我添加了一个vbtab来输出输出,结果如下:
<L5fmModalBody files={this.state.data.files} />
非常感谢您的支持!