[python-win32] Getting the associated icon of a file type
Richard Philips
richard.philips at ua.ac.be
Mon Aug 4 11:20:56 EDT 2003
Hello all,
How can I retrieve the associated icon of a file type ?
I tried the following:
def getDefaultIcon(filename):
'''Retrieve the default icon of a filename'''
(root, extension) = os.path.splitext(filename)
if extension:
value_name = _winreg.QueryValue(_winreg.HKEY_CLASSES_ROOT,
extension)
try:
value_name = _winreg.QueryValue(_winreg.HKEY_CLASSES_ROOT,
extension)
except _winreg.error:
value_name = None
else:
value_name = None
if value_name:
try:
icon = _winreg.QueryValue(_winreg.HKEY_CLASSES_ROOT,
value_name + "\\DefaultIcon")
except _winreg.error:
icon = None
else:
icon = None
return icon
if __name__ == "__main__":
print getDefaultIcon("icon.html")
print getDefaultIcon("icon.py")
This works fine.
The result is:
1) None
2) *.ico file (e.g. D:\Python\Py.ico)
3) *.dll, *.exe
4) "%1" (e.g. .html -> "%1")
1) and 2) are ok for me.
3) and 4) pose problems.
Any help on this issue would be helpful.
Thanks,
Richard
--
================================================================
Dr. Richard PHILIPS
University of Antwerp
Systemmanager Anet
Phone: +32 3 820.21.53
Fax: +32 3 820.21.59
GSM: 0478/36.76.28
Email: Richard.Philips at ua.ac.be
================================================================
More information about the Python-win32
mailing list