使用VBA获取扩展文件属性
尝试使用 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):
- File Path
- File Name
- File Size
- Date Created
- Date Last Accessed
- Date Last Modified
- File Type
Would also like to capture the extended properties that come from the file itself:
- Author
- Keywords
- Comments
- Last Author
- Category
- Subject
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你说循环..所以如果你想对目录而不是当前文档执行此操作;
其中XXX是属性列索引,例如Author为9。
要列出可用索引供您参考,您可以将 for 循环替换为;
快速获取单个文件/属性:
You say loop .. so if you want to do this for a dir instead of the current document;
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;
Quickly for a single file/attribute:
您可以通过
.BuiltInDocmementProperties
获得此信息。例如:
请参阅此页面,了解可以通过以下方式访问的所有字段: http:// /msdn.microsoft.com/en-us/library/bb220896.aspx
如果您尝试在客户端外部执行此操作(即关闭 Excel 并运行 .NET 程序中的代码),您需要使用 DSOFile .dll。
You can get this with
.BuiltInDocmementProperties
.For example:
See this page for all the fields you can access with this: http://msdn.microsoft.com/en-us/library/bb220896.aspx
If you're trying to do this outside of the client (i.e. with Excel closed and running code from, say, a .NET program), you need to use DSOFile.dll.
我终于能够让它满足我的需求。
旧的投票代码不能在 Windows 10 系统上运行(至少不是我的)。下面引用的 MS 库链接提供了有关如何实现此功能的最新示例。我的示例将它们与后期绑定一起使用。
https://learn.microsoft.com/en-us/ windows/win32/shell/folder-getdetailsof。
我的计算机上的属性代码有所不同,就像上面提到的那样,大多数属性代码都会返回空白值,即使它们不是。我使用 for 循环遍历所有这些内容,发现标题和主题仍然可以访问,这对于我的目的来说已经足够了。
I was finally able to get this to work for my needs.
The old voted up code does not run on windows 10 system (at least not mine). The referenced MS library link below provides current examples on how to make this work. My example uses them with late bindings.
https://learn.microsoft.com/en-us/windows/win32/shell/folder-getdetailsof.
The attribute codes were different on my computer and like someone mentioned above most return blank values even if they are not. I used a for loop to cycle through all of them and found out that Title and Subject can still be accessed which is more then enough for my purposes.
幸运的是
,当您调用时,如果
objFolderItem
is Nothing,则返回的字符串是属性的名称,而不是其(未定义的)值
例如,当
i=3
时,它返回“修改日期”对 I 的所有 288 个值执行此操作,可以清楚地了解为什么大多数文件类型会导致它返回空白
例如
i=175
是“水平分辨率”Lucky discovery
if
objFolderItem
is Nothing when you callthe string returned is the name of the property, rather than its (undefined) value
e.g. when
i=3
it returns "Date modified"Doing it for all 288 values of I makes it clear why most cause it to return blank for most filetypes
e.g
i=175
is "Horizontal resolution"