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

Tim Golden mail at timgolden.me.uk
Fri Jun 17 15:54:26 CEST 2011


On 17/06/2011 14:19, reckoner wrote:
> Is it possible to get access to the Most Recently Used (MRU) list in
> windows. This is where Windows keeps a list of the most recently opened
> documents and programs.
>
> By the way, I'm on Windows XP.

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


More information about the python-win32 mailing list