首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过Python自定义文件夹的图标?

如何通过Python自定义文件夹的图标?
EN

Stack Overflow用户
提问于 2014-11-06 09:41:18
回答 1查看 2K关注 0票数 3

正如这个苏回答所指出的,为了更改文件夹的图标,必须将文件夹的属性更改为只读或系统,并使其desktop.ini包含以下内容

代码语言:javascript
复制
[.ShellClassInfo]
IconResource=somePath.dll,0

虽然使用win32api.SetFileAttributes(dirpath, win32con.FILE_ATTRIBUTE_READONLY)并从头创建desktop.ini很简单,但我希望保留可能存在的desktop.ini中的其他自定义。但是,我是否应该为此使用ConfigParser,或者win32api (或者ctypes.win32)是否提供了这样做的本地方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-13 11:16:31

好的,所以从这条线,我设法使一些工作。我希望它能对你有帮助。

下面是我的基本desktop.ini文件:

代码语言:javascript
复制
[.ShellClassInfo]
IconResource=somePath.dll,0

[Fruits]
Apple = Blue
Strawberry = Pink

[Vegies]
Potatoe = Green
Carrot = Orange

[RandomClassInfo]
foo = somePath.ddsll,0

下面是我使用的脚本:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
[.ShellClassInfo]
iconresource = somePath.dll,0

[Fruits]
apple = Green
strawberry = Red

[Vegies]
potatoe = Green
carrot = Orange

[RandomClassInfo]
foo = somePath.ddsll,0

我唯一的问题是,这些选项正在失去他们的第一个字母大写字母。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26776070

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档