[python-win32] Access Most Recently Used (MRU) entries ?

Tim Golden mail at timgolden.me.uk
Sun Jun 19 23:19:21 CEST 2011


On 19/06/2011 00:00, reckoner wrote:
>
>> On 17/06/2011 14:19, reckoner wrote:
>>
>> Depends what you need to do. To add in item, use the SHAddToRecentDocs
>> API from the shell module:
>>
>> <code>
>> import sys
>> from win32com.shell import shell, shellcon
>>
>> shell.SHAddToRecentDocs (
>> shellcon.SHARD_PATHW,
>> sys.executable
>> )
>>
>> </code>
>>
>> To access its contents (in file system terms):
>>
>> <code>
>> import os, sys
>> from win32com.shell import shell, shellcon
>>
>> mru = shell.SHGetSpecialFolderPath (0, shellcon.CSIDL_RECENT, 0)
>> print os.listdir (mru)
>>
>> </code>
>>
>> To access it as shell folder:
>>
>> <code>
>> import os, sys
>> from win32com.shell import shell, shellcon
>>
>> mru_pidl = shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_RECENT)
>> desktop = shell.SHGetDesktopFolder ()
>> mru_folder = desktop.BindToObject (
>> mru_pidl,
>> None,
>> shell.IID_IShellFolder
>> )
>>
>> for i in mru_folder:
>> print mru_folder.GetDisplayNameOf (i, shellcon.SHGDN_NORMAL)
>>
>> </code>
>>
>> TJG
>
>
> Thank you! This is a big help. Is there a way to find out which program
> called which item in the MRU list and when that occurred?

Not AFAIK. However, you can assume that the program
associated with the file extension created the link and that the
time the link was created was when it occurred. You can find the
associated program with the win32api.FindExecutable API and the
standard os.getmtime will tell you when the link was created.

TJG


More information about the python-win32 mailing list