Reputation: 57
When you right-click a file in Windows Explorer and select Properties from the menu, a dialog box displays basic properties for that file.
I'm trying to get these properties (keywords, comments, title...) for word files in a folder.
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
So I'm trying to make it work in object pascal in delphi. I'm still missing some of the syntax.
I was able to transform half 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'
Can anyone help me out please?
Upvotes: 3
Views: 2593
Reputation: 613053
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;
The code looks a little odd though, especially the use of that magic value 35.
Upvotes: 3