使用 VBA 获取扩展文件属性 [英] Using VBA to get extended file attributes
问题描述
尝试使用 Excel VBA 从 磁盘上的文件 中捕获所有文件属性,包括扩展属性.能够让它遍历文件并捕获基本属性(来自文件系统):
Trying to use Excel VBA to capture all the file attributes from files on disk, including extended attributes. Was able to get it to loop through the files and capture the basic attributes (that come from the file system):
- 文件路径
- 文件名
- 文件大小
- 创建日期
- 上次访问日期
- 上次修改日期
- 文件类型
还想捕获来自文件本身的扩展属性:
Would also like to capture the extended properties that come from the file itself:
- 作者
- 关键字
- 评论
- 最后作者
- 类别
- 主题
以及右键单击文件时可见的其他属性.
And other properties which are visible when right clicking on the file.
目标是创建文件服务器上所有文件的详细列表.
The goal is to create a detailed list of all the files on a file server.
推荐答案
你说 loop .. 所以如果你想为一个目录而不是当前文档这样做;
You say loop .. so if you want to do this for a dir instead of the current document;
Dim sFile As Variant
Dim oShell: Set oShell = CreateObject("Shell.Application")
Dim oDir: Set oDir = oShell.Namespace("c:foo")
For Each sFile In oDir.Items
Debug.Print oDir.GetDetailsOf(sFile, XXX)
Next
其中 XXX 是属性列索引,例如 Author 为 9.要列出可用索引供您参考,您可以将 for 循环替换为;
Where XXX is an attribute column index, 9 for Author for example. To list available indexes for your reference you can replace the for loop with;
for i = 0 To 40
debug.? i, oDir.GetDetailsOf(oDir.Items, i)
Next
快速获取单个文件/属性:
Quickly for a single file/attribute:
Const PROP_COMPUTER As Long = 56
With CreateObject("Shell.Application").Namespace("C:HOSTDIRECTORY")
MsgBox .GetDetailsOf(.Items.Item("FILE.NAME"), PROP_COMPUTER)
End With
这篇关于使用 VBA 获取扩展文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!