Recent

Author Topic: Getting extended file properties  (Read 1926 times)

MaartenW

  • New member
  • *
  • Posts: 9
Getting extended file properties
« on: April 07, 2020, 02:36:32 pm »
In Windows Explorer, extended file properties can be seen by showing extra columns.
I try to get this information programmatically, but have limited succes.

Code: Pascal  [Select][+][-]
  1. const
  2.   saHeader : array [0..7] of string = (
  3.     'File',
  4.     'Meewerkende artiesten',
  5.     'Album',
  6.     'Jaar',
  7.     'Auteurs',
  8.     'Titel',
  9.     'AlbumArtiest',
  10.     'Componisten'
  11.     );
  12. var
  13.   Shell : Variant;
  14.   OleFolder : OleVariant;
  15.   OleFolderItem, OleDetail: OleVariant;
  16.   VsFilePath : Variant;
  17.   VsFileName : Variant;
  18.   PpPropNaam : TBSTR; //POleStr; //PWideChar;
  19. begin
  20.   Shell := CreateOleObject('Shell.Application');
  21.   VsFilePath := Directory;
  22.   OleFolder := Shell.Namespace(VsFilePath);
  23.   VsFileName := ExtractFileName(FileName);
  24.   OleFolderItem := OleFolder.ParseName(VsFileName);
  25.  
  26.   ExtProp := OleFolderItem.ExtendedProperty('Album'); //<---- results in correct value
  27.  
  28.   ExtProp := OleFolderItem.ExtendedProperty('Meewerkende artiesten'); //<---- results in empty value (should be filled)
  29.  
  30.   PpPropNaam := SysAllocString(Pointer(saHeader[2]));
  31.   ExtProp := OleFolderItem.ExtendedProperty(PpPropNaam); //<---- compiler: Type is not automatable: "PWideChar"
  32.  
(I have W10 Dutch, Lazarus 2.0.6)

Using a fixed string without space, a correct value results.
Using a fixed string with a space, a blanc value results.
Using a variable TBSTR (as documented in MS documentation) results in a compiler-error.

What should I do to get correct values for
(1) fixed strings containing space(s)
(2) using variables representing strings?

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: Getting extended file properties
« Reply #1 on: April 07, 2020, 02:44:45 pm »
Is it better to use the Windows API directly?
See topic: how to get the original filedate not date modifyed.

MaartenW

  • New member
  • *
  • Posts: 9
Re: Getting extended file properties
« Reply #2 on: April 07, 2020, 03:00:46 pm »
Hi ASerge, thanks for your answer. I appreciate!

In your reference a GUID is used. This is advised by Microsoft for speed-reasons . The same for some ID number. Theoretically this is a good solution, however, I prefer to make readable code.
In Microsoft's documentation it is stated that a TBSRT string can be used to get the value. Using this, readable code can be written which can be maintained after a long time.

So yes, GUID or ID could be used, but I do prefer readable string variables.

Having this demand, how should I solve this?
« Last Edit: April 07, 2020, 03:04:38 pm by MaartenW »

rvk

  • Hero Member
  • *****
  • Posts: 6056
Re: Getting extended file properties
« Reply #3 on: April 07, 2020, 04:49:53 pm »
Code: [Select]
  ExtProp := OleFolderItem.ExtendedProperty('Meewerkende artiesten'); //<---- results in empty value (should be filled)
How about
Code: [Select]
  ExtProp := OleFolderItem.ExtendedProperty('Contributing artists');
Although your Windows version might be Dutch, it could be just a translation in the Explorer and not for the actual properties.

rvk

  • Hero Member
  • *****
  • Posts: 6056
Re: Getting extended file properties
« Reply #4 on: April 07, 2020, 05:29:51 pm »
By the way... if 'Contributing artists' doesn't work you can always loop through all properties and check if the property-name is 'Contributing artists'.

Something like:
Code: Pascal  [Select][+][-]
  1.   I := 0;
  2.   PropName := OleFolder.GetDetailsOf(null, I); // with null you'll get the property name
  3.   while PropName <> '' do
  4.   begin
  5.     PropValue := OleFolder.GetDetailsOf(OleFolderItem, I); // with item you get the value
  6.     Memo1.Lines.Add(Format('%s = %s', [PropName, PropValue]));
  7.  
  8.     if uppercase('Contributing artists') = uppercase(PropName) then
  9.       Memo1.Lines.Add('YES, THIS IS IT');
  10.  
  11.     I := I + 1;
  12.     PropName := OleFolder.GetDetailsOf(null, I);
  13.   end;
You can create a function which extracts your desired property yourself.

MaartenW

  • New member
  • *
  • Posts: 9
Re: Getting extended file properties
« Reply #5 on: April 07, 2020, 07:37:40 pm »
Thanks for your suggestion, Rik.

In all my testing I got the values from 'OleFolder.GetDetailsOf(OleFolder.Items, I);'. These are all Dutch.

With 'Contributing Artists' no result was found.
Any variabletype used in 'OleFolderItem.ExtendedProperty(PpPropNaam);' results in an empty result. Only a real string ('Album') results in a correct value.

I think of using the result of the list from 'GetDetails' to search for the GetDetailsOf(OleFolderItem, iCN), where iCN is the index of the string corresponding with 'I' in the line above. This is a workaround, but less complex to understand after several months (when maintenance mau be needed than using GUID complexity.

Thanks all for the suggestions.
When anyone may have a better suggestion, feel free to bring the world a tiny bit forward. :D

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: Getting extended file properties
« Reply #6 on: April 08, 2020, 01:27:53 am »
So yes, GUID or ID could be used, but I do prefer readable string variables.
Readable string are language depended.

 

TinyPortal © 2005-2018