2014-11-06 1 views
2

this SU answer으로 노트, 폴더의 아이콘을 변경하기 위해, 하나는 읽기 전용 또는 시스템 폴더의 속성을 변경하고 win32api.SetFileAttributes(dirpath, win32con.FILE_ATTRIBUTE_READONLY)를 사용하는 간단한 것 동안의 desktop.iniPython을 통해 폴더의 아이콘을 사용자 정의하는 방법은 무엇입니까?

[.ShellClassInfo] 
IconResource=somePath.dll,0 

같은 것을 포함해야한다 처음부터 desktop.ini을 만들려면 잠재적 인 기존 desktop.ini에있는 다른 맞춤 설정을 보존하고 싶습니다. 하지만이를 위해 ConfigParser을 사용해야합니까? 예 : win32api (또는 아마도 ctypes.win32) 이렇게하는 고유 한 방법을 제공합니까?

+0

(지금까지 찾은 유일한 사용자 지정 관련 기능은 [SHSetLocalizedName] (http://msdn.microsoft.com/en-us/library/windows/desktop/bb762250%28v=vs.85%29.aspx)입니다.)) –

+0

안녕하세요,이 스레드는 오래되어 있지 않으므로 답변을 찾았는지 직접 물어볼 수 있습니다. 나는 현재 같은 문제에 직면하고있다. – DrHaze

+0

@DrHaze 불행히도 저는 처음부터 desktop.ini를 사용했습니다 ... 아마도이 질문에 대한 작은 현상금은 누군가가 자신의 발견을보고하도록 동기를 부여합니다. –

답변

1

좋아, 그래서 this thread에서, 나는 일하는 것을 얻을 수 있었다. 나는 그것이 당신을 도울 것이기를 바랍니다. 출력있는 Desktop.ini 파일 여기

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) 

됩니다 :

[.ShellClassInfo] 
iconresource = somePath.dll,0 

[Fruits] 
apple = Green 
strawberry = Red 

[Vegies] 
potatoe = Green 
carrot = Orange 

[RandomClassInfo] 
foo = somePath.ddsll,0 

여기

[.ShellClassInfo] 
IconResource=somePath.dll,0 

[Fruits] 
Apple = Blue 
Strawberry = Pink 

[Vegies] 
Potatoe = Green 
Carrot = Orange 

[RandomClassInfo] 
foo = somePath.ddsll,0 

내가 사용하는 스크립트입니다 : 여기

내 기본있는 Desktop.ini 파일입니다 내가 가진 유일한 문제는 옵션이 첫 글자 대문자를 잃어 버리고 있다는 것입니다.

+0

방금 ​​테스트했는데 케이스 손실은 iconresource의 동작에 영향을 미치지 않습니다. – DrHaze

+0

문제는 네트워크 공유에서이 문제를 시도했지만 설치가 변경된 후에 오류가 재현되지 않는다는 것입니다. –

+1

소문자 문제는 ['config.optionxform = str'] (https : // stackoverflow)로 해결할 수 있습니다. .com/a/1611877/321973) –

관련 문제