Copy file information from explorer as tabular text

I'm looking for a way to easily copy the file data that is displayed in Windows Explorer (detailed view) and paste it as tabular text.

Ideally, the procedure would be to select some files in the explorer, make a selection in the context menu (or use a keyboard shortcut), and the list will be copied to the clipboard. When pasting, the table format will be preserved so Excel recognizes columns or Word keep tabs (or creates a table).

I would like to have a solution that passes the available columns, not just predefined data like name + size + date.

Do you think there is an easy way to achieve this functionality? I'm willing to program in any language if needed, but I need a path to follow. I also need a procedure to integrate it into Windows (Vista and later) so that a few clicks are enough.

+3


source to share


1 answer


1) Create a shell extension of the context menu. It should implement IShellExtInit, IContextMenu (2,3) and IObjectWithSite. Register the shell extension on the HKCR \ AllFilesystemObjects key.

2) Before Explorer calls IContextMenu.InvokeCommand, it calls IObjectWithSite.SetSite. Save site value.

3) Inside IContextMenu.InvokeCommand:

Site.QueryInterface(IServiceProvider, ServiceProvider)
ServiceProvider.QueryService(SID_SFolderView, IColumnManager, ColumnManager)
ColumnManager.GetColumnCount(CM_ENUM_VISIBLE, Count)
GetMem(Keys, SizeOf(PPropertyKey) * Count)
ColumnManager.GetColumns(CM_ENUM_VISIBLE, Keys, Count)

      

You now have an array of all visible columns.

4) Extract the IShellFolder of the current folder from the IDataObject passed to your handler in IShellExtInit.Initialize.

5) Extract PItemIDList from each file in IDataObject.

6) For each PItemIDList:

6.1) Call ShellFolder.BindToObject (Child, nil, IPropertyStore, PropertyStore) to get the PropertyStore of the item.

6.2) For each array PropertyKey in Keys:

6.2.1) Call PropertyStore.GetValue (PropertyKey, Value);



6.2.2) Converting a value to a string using the PropVariantToStringAlloc function.

6.2.3) Store the string representation of the value in your internal txt storage.

7) Copy the txt repository to the clipboard.

8) Free up all resources.

Update 1

Also you can try using IShellFolder2.GetDetailsEx instead of using IPropertyStore.

Update 2

If using IPropertyStore, you can optionally call IPropertySystem.FormatForDisplayAlloc to format the value. For example, for PKEY_Size PropertyStore.GetValue returns "100000", but PropertySystem.FormatForDisplayAlloc will format the value to "100KB".

Update 3

This was a pretty interesting task, so I created my own shell extension that copies the details to the clipboard. It can be downloaded from the link http://www.shellace.com/bin/CopyDetails.zip

+2


source







All Articles