通过delphi检索扩展文件属性 [英] Retrieving Extended File Properties via delphi

查看:46
本文介绍了通过delphi检索扩展文件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows资源管理器中右键单击文件并从菜单中选择属性"时,将显示一个对话框,显示该文件的基本属性.

When you right-click a file in Windows Explorer and select Properties from the menu, a dialog box displays basic properties for that file.

我正在尝试获取文件夹中Word文件的这些属性(关键字,注释,标题...).

I'm trying to get these properties (keywords, comments, title...) for word files in a folder.

我修改了在某处找到的代码,该代码在vba(MSWord Office宏)中运行良好:

I modified a code that i found somewhere and it works well in vba (MSWord office macro):

Private Sub CommandButton1_Click()

Dim arrHeaders(35)

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Scripts")

For i = 0 To 34
  arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next

For Each FileName In objFolder.Items
  For i = 0 To 34
    MsgBox i & vbTab & arrHeaders(i) & ": " & objFolder.GetDetailsOf(FileName, i)
  Next
Next

End Sub

因此,我正在尝试使其在delphi中的对象pascal中工作.我仍然缺少一些语法.

So I'm trying to make it work in object pascal in delphi. I'm still missing some of the syntax.

我能够转换一半语法:

procedure TFormAFDetails.Button1Click(Sender: TObject);
var
  ObjShell, ObjFolder : Variant;
  FileProp : array of string;
  FName : String;
  I, J : Integer;
begin
    SetLength(FileProp, 35);
    ObjShell := CreateOleObject('Shell.Application');
    ObjFolder := ObjShell.NameSpace('C:\Scripts');

    for I := 0 to 34 do
      FileProp[I] := ObjFolder.GetDetailsOf(ObjFolder.Items,I);

    for FName in ObjFolder.Items do
    begin
      for J := 0 to 34 do
        ShowMessage(FileProp[J]+' : '+ObjFolder.GetDetailsOf(FName,J));
    end;
end;

为-做-做"部分无法正常工作

The part "for - in - do" won't work as it says

//for -in statement can't operate on collection type 'variant' 

有人可以帮我吗?

推荐答案

您提出的问题的答案是:

The answer to the question that you ask is:

for I := 0 to ObjFolder.Items.Count-1 do
begin
  FName := ObjFolder.Items.Item(I);
  ....
end;    

虽然代码看起来有些奇怪,尤其是使用该魔术值35.

The code looks a little odd though, especially the use of that magic value 35.

这篇关于通过delphi检索扩展文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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