windows - How to customize a folder's icon via Python? -
windows - How to customize a folder's icon via Python? -
as this su answer notes, in order alter folder's icon, 1 has alter folder's attribute read-only or system, , have desktop.ini
contain like
[.shellclassinfo] iconresource=somepath.dll,0
while straightforward utilize win32api.setfileattributes(dirpath, win32con.file_attribute_readonly)
, create desktop.ini
scratch, i'd preserve other customizations nowadays in potentially existing desktop.ini
. should utilize configparser or e.g. win32api
(or maybe ctypes.win32
) provide native means so?
ok, this thread, managed working. hope help you.
here base of operations desktop.ini file:
[.shellclassinfo] iconresource=somepath.dll,0 [fruits] apple = bluish strawberry = pinkish [vegies] potatoe = greenish carrot = orange [randomclassinfo] foo = somepath.ddsll,0
here script use:
from configparser import rawconfigparser dict = {"fruits":{"apple":"green", "strawberry":"red"},"vegies":{"carrot":"orange"} } # config object config = rawconfigparser() # read file 'desktop.ini' config.read(r'c:\path\to\desktop.ini') section in dict.keys(): alternative in dict[section]: try: # read value section 'fruit', alternative 'apple' currentval = config.get( section, alternative ) print "current value of " + section + " - " + alternative + ": " + currentval # if value not right 1 if currentval != dict[section][option]: print "replacing value of " + section + " - " + alternative + ": " + dict[section][option] # set value 'llama' config.set( section, option, dict[section][option]) except: print "could not find " + section + " - " + alternative # rewrite configuration .ini file open(r'c:\path\to\desktop.ini', 'w') myconfig: config.write(myconfig)
here output desktop.ini file:
[.shellclassinfo] iconresource = somepath.dll,0 [fruits] apple = greenish strawberry = reddish [vegies] potatoe = greenish carrot = orange [randomclassinfo] foo = somepath.ddsll,0
the problem have options loosing first letter uppercase.
python windows desktop.ini
Comments
Post a Comment