使用VBA获取扩展文件属性 [英] Using VBA to get extended file attributes

查看:327
本文介绍了使用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):

  • 文件路径
  • 文件名
  • 文件大小
  • 创建日期
  • 上次访问日期
  • 上次修改日期
  • 文件类型

还希望捕获来自文件本身的扩展属性:

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.

推荐答案

您说循环..因此,如果要对目录而不是当前文档执行此操作;

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是属性列索引,例如,作者为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆