Based on the comments above, it looks like you decided to go the other direction with this. Your question aroused my curiosity, although I still hunted around.
File associations are stored in the Windows registry. The way to access Windows registry information through python is to use the _winreg module (available in versions 2.0 and later). Individual file association information for the current user will be stored in subsections named as follows:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.wmv\UserChoices
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mpeg\UserChoices
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.avi\UserChoices
etc. for any particular file format you are looking for.
Here is a small example script that I wrote to access this information and saved it as a list:
import _winreg as wr
videoFormats = ('.wmv', '.avi', '.mpeg')
userOpenPref = []
for i in videoFormats:
subkey = ("Software\\Microsoft\\Windows\\CurrentVersion" +
"\\Explorer\\FileExts\\" + i + "\\UserChoice")
explorer = wr.OpenKey(wr.HKEY_CURRENT_USER, subkey)
try:
i = 0
while 1:
userOpenPref.append(wr.EnumValue(explorer, i)[1])
i += 1
except WindowsError:
print
explorer.Close()
print userOpenPref
Conclusion:
[u'WMP11.AssocFile.WMV', u'WMP11.AssocFile.avi', u'WMP11.AssocFile.MPEG']
with WMP11 = Windows Media Player 11
Hope this was helpful.
Sources:
python docs , effbot tutorial
source
share