Created
September 29, 2021 14:11
-
-
Save J0B10/3cf3315370234f6c27b535ffe2ad4bcd to your computer and use it in GitHub Desktop.
Changes folder icons if the folder contains a .ico file with the right name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
for root, dirs, files in os.walk("."): | |
for file in files: | |
if file.endswith(".ico"): | |
path = os.path.abspath(os.path.join(root, file)) | |
parent= os.path.dirname(path) | |
parentName = os.path.basename(parent) | |
if "." + parentName.lower() + ".ico" == file: | |
print("Updating icon of '%s'" % parentName) | |
os.system("attrib +H \"" + path + "\"") | |
iniFile = os.path.join(parent, "desktop.ini") | |
iniTxt = os.path.join(parent, "desktop.txt") | |
with open(iniTxt, "w") as ini: | |
ini.write("[.ShellClassInfo]\n") | |
ini.write("IconResource=%s,0\n" % path) | |
ini.write("[ViewState]\n") | |
ini.write("Mode=\n") | |
ini.write("Vid=\n") | |
ini.write("FolderType=StorageProviderPictures\n") | |
os.system("move \"{}\" \"{}\"".format(iniTxt, iniFile)) | |
os.system("attrib +H +S \"" + iniFile + "\"") | |
os.system("attrib +R \"" + parent + "\"") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment