フォルダアイコンの設定と削除


メモメモ

from win32api import *
from win32con import *

def set_folder_icon(dirpath, iconpath, iconindex=0):
    desktopini_path = os.path.join(dirpath, "desktop.ini")
    WriteProfileVal(".ShellClassInfo", "IconFile", iconpath, desktopini_path)
    WriteProfileVal(".ShellClassInfo", "IconIndex", iconindex, desktopini_path)
    SetFileAttributes(dirpath, GetFileAttributes(dirpath) | FILE_ATTRIBUTE_SYSTEM)

def clear_icon_from_desktop_ini(dirpath):
    desktopini_path = os.path.abspath(os.path.join(dirpath, "desktop.ini"))
    WriteProfileVal(".ShellClassInfo", "IconFile", "", desktopini_path)
    WriteProfileVal(".ShellClassInfo", "IconIndex", "", desktopini_path)