"change folder icon with python" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "change folder icon with python" answered properly. Developers are finding an appropriate answer about change folder icon with python related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like change folder icon with python. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on change folder icon with python.
change folder icon with python
import os
import ctypes
from ctypes import POINTER, Structure, c_wchar, c_int, sizeof, byref
from ctypes.wintypes import BYTE, WORD, DWORD, LPWSTR, LPSTR
import win32api
HICON = c_int
LPTSTR = LPWSTR
TCHAR = c_wchar
MAX_PATH = 260
FCSM_ICONFILE = 0x00000010
FCS_FORCEWRITE = 0x00000002
SHGFI_ICONLOCATION = 0x000001000
class GUID(Structure):
_fields_ = [
('Data1', DWORD),
('Data2', WORD),
('Data3', WORD),
('Data4', BYTE * 8)]
class SHFOLDERCUSTOMSETTINGS(Structure):
_fields_ = [
('dwSize', DWORD),
('dwMask', DWORD),
('pvid', POINTER(GUID)),
('pszWebViewTemplate', LPTSTR),
('cchWebViewTemplate', DWORD),
('pszWebViewTemplateVersion', LPTSTR),
('pszInfoTip', LPTSTR),
('cchInfoTip', DWORD),
('pclsid', POINTER(GUID)),
('dwFlags', DWORD),
('pszIconFile', LPTSTR),
('cchIconFile', DWORD),
('iIconIndex', c_int),
('pszLogo', LPTSTR),
('cchLogo', DWORD)]
class SHFILEINFO(Structure):
_fields_ = [
('hIcon', HICON),
('iIcon', c_int),
('dwAttributes', DWORD),
('szDisplayName', TCHAR * MAX_PATH),
('szTypeName', TCHAR * 80)]
def seticon(folderpath, iconpath, iconindex):
"""Set folder icon.
>>> seticon(".", "C:\\Windows\\system32\\SHELL32.dll", 10)
"""
shell32 = ctypes.windll.shell32
folderpath = unicode(os.path.abspath(folderpath), 'mbcs')
iconpath = unicode(os.path.abspath(iconpath), 'mbcs')
fcs = SHFOLDERCUSTOMSETTINGS()
fcs.dwSize = sizeof(fcs)
fcs.dwMask = FCSM_ICONFILE
fcs.pszIconFile = iconpath
fcs.cchIconFile = 0
fcs.iIconIndex = iconindex
hr = shell32.SHGetSetFolderCustomSettings(byref(fcs), folderpath,
FCS_FORCEWRITE)
if hr:
raise WindowsError(win32api.FormatMessage(hr))
sfi = SHFILEINFO()
hr = shell32.SHGetFileInfoW(folderpath, 0, byref(sfi), sizeof(sfi),
SHGFI_ICONLOCATION)
if hr == 0:
raise WindowsError(win32api.FormatMessage(hr))
index = shell32.Shell_GetCachedImageIndexW(sfi.szDisplayName, sfi.iIcon, 0)
if index == -1:
raise WindowsError()
shell32.SHUpdateImageW(sfi.szDisplayName, sfi.iIcon, 0, index)
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on change folder icon with python can get a collection of related answers to their query. Programmers need to enter their query on change folder icon with python related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about change folder icon with python for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of change folder icon with python while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "change folder icon with python". Visit this developer's friendly online web community, CodeProZone, and get your queries like change folder icon with python resolved professionally and stay updated to the latest Whatever updates.