Recent

Author Topic: How to get file attributes using unit shlobj ?  (Read 1374 times)

Borneq

  • Full Member
  • ***
  • Posts: 238
How to get file attributes using unit shlobj ?
« on: January 29, 2020, 08:07:43 pm »
I can walk through folders starting at SHGetDesktopFolder, next I do SHGetSpecialFolderLocation, next FIDesktopFolder.BindToObject and ShellFolder.EnumObjects. I can get path and display name by ShellFolder.GetDisplayNameOf.
But
how can file size and file modification time?
Is struct FILEDESCRIPTOR but i can't find any function that uses it.
« Last Edit: January 29, 2020, 08:18:37 pm by Borneq »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 825
    • Lebeau Software
Re: How to get file attributes using unit shlobj ?
« Reply #1 on: January 29, 2020, 08:27:00 pm »
But how can file size and file modification time?

You can use IShellFolder.BindToStorage() and then IStorage.Stat() or IStream.Stat().

Or, have a look at IShellFolder2, which has GetDetailsOf() and GetDetailsEx() methods.

Or, consider using IShellItem instead of IShellFolder.  IShellFolder is an old API.  IShellItem2 has GetFileTime() and GetUInt64(PKEY_Size) methods.

Otherwise, you can just use the filesystem API instead, using the path you retrieve from each shell item to call GetFileSize() and GetFileTime(), or GetFileAttributesEx(GetFileExInfoStandard).
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Borneq

  • Full Member
  • ***
  • Posts: 238
Re: How to get file attributes using unit shlobj ?
« Reply #2 on: January 29, 2020, 08:33:10 pm »
In ShellApi unit are SHGetFileInfo functions (is needed path).
I try use newer IShellItem but I don't see IShellItem2, only
Code: Pascal  [Select][+][-]
  1.     PIShellItem= ^IShellItem;
  2.     IShellItem = interface(IUnknown)
  3.                ['{43826d1e-e718-42ee-bc55-a1e261c37bfe}']
  4.                function BindToHandler(pbc:IBindCTX;bhid:PGUID;RIID:PIID;ppv:ppointer):HResult;Stdcall;          
  5.                function GetParent(ppsi:PISHellItem):HResult;Stdcall;
  6.                function GetDisplayName(sigdnname:SIGDN;ppszName:LPWSTR):HResult; Stdcall;
  7.                function GetAttributes(sfgaomask:SFGAOF;psfgaoAttribs:PSFGAOF):HResult;Stdcall;
  8.                function Compare(psi:IShellItem;hint:SICHINTF;piorder:PINT):HResult; Stdcall;
  9.                end;    

Borneq

  • Full Member
  • ***
  • Posts: 238
Re: How to get file attributes using unit shlobj ?
« Reply #3 on: January 29, 2020, 08:52:51 pm »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 825
    • Lebeau Software
Re: How to get file attributes using unit shlobj ?
« Reply #4 on: February 01, 2020, 03:38:28 am »
In ShellApi unit are SHGetFileInfo functions (is needed path).

That function does not provide the information you are asking for (file size, modification time, etc).

I try use newer IShellItem but I don't see IShellItem2

Then you will have to define it manually in your own code, based on the definition provided on MSDN, or I'm sure you can find a Pascal translation online if you look around.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018