Хорошо, поэтому от this thread мне удалось получить что-то работающее. Надеюсь, это вам поможет.
Вот моя база desktop.ini файл:
[.ShellClassInfo]
IconResource=somePath.dll,0
[Fruits]
Apple = Blue
Strawberry = Pink
[Vegies]
Potatoe = Green
Carrot = Orange
[RandomClassInfo]
foo = somePath.ddsll,0
Вот скрипт я использую:
from ConfigParser import RawConfigParser
dict = {"Fruits":{"Apple":"Green", "Strawberry":"Red"},"Vegies":{"Carrot":"Orange"} }
# Get a config object
config = RawConfigParser()
# Read the file 'desktop.ini'
config.read(r'C:\Path\To\desktop.ini')
for section in dict.keys():
for option in dict[section]:
try:
# Read the value from section 'Fruit', option 'Apple'
currentVal = config.get(section, option)
print "Current value of " + section + " - " + option + ": " + currentVal
# If the value is not the right one
if currentVal != dict[section][option]:
print "Replacing value of " + section + " - " + option + ": " + dict[section][option]
# Then we set the value to 'Llama'
config.set(section, option, dict[section][option])
except:
print "Could not find " + section + " - " + option
# Rewrite the configuration to the .ini file
with open(r'C:\Path\To\desktop.ini', 'w') as myconfig:
config.write(myconfig)
Здесь выходной файл desktop.ini:
[.ShellClassInfo]
iconresource = somePath.dll,0
[Fruits]
apple = Green
strawberry = Red
[Vegies]
potatoe = Green
carrot = Orange
[RandomClassInfo]
foo = somePath.ddsll,0
Единственная проблема, с которой я сталкиваюсь, заключается в том, что опции теряют свою первую букву в верхнем регистре.
(единственная связанная с настройкой функция, которую я нашел до сих пор, - [SHSetLocalizedName] (http://msdn.microsoft.com/en-us/library/windows/desktop/bb762250%28v=vs.85%29.aspx)) –
Привет, поскольку эта ветка не так уж и старая, я позволю себе спросить вас, нашли ли вы ответ. В настоящее время я сталкиваюсь с той же проблемой. – DrHaze
@DrHaze, к сожалению, я застрял с desktop.ini с нуля до сих пор ... может быть, небольшая щедрость по этому вопросу помогает мотивировать кого-то сообщать о своих результатах. –