├── .gitignore ├── FolderIconTool.py ├── README.md ├── TestEnvironment ├── Folder.ico ├── FolderIconTool-TestEnvironment.rar ├── 书籍 │ └── iBooks Author.ico ├── 游戏 │ └── Game Center.ico ├── 软件 │ └── App Store.ico └── 音乐 │ └── iTunes.ico └── imges ├── FolderIconTool.ico ├── FolderIconTool.png └── HowToUseFolderIconTool.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /FolderIconTool.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | import os 4 | import stat 5 | 6 | ## 总体思路: 7 | ## 1. 检测当前目录下是否有 .ico 文件。 8 | ## 2. 将文件夹设置为只读。 9 | ## 3. 在每个有图标的目录中新建 desktop.ini 文件,设为隐藏。 10 | 11 | def main(): 12 | 13 | ## -----说明文字----- 14 | print ("=======================================") 15 | print ("- 欢迎使用 FolderIconTool") 16 | print ("- Design by fengyunkkx") 17 | print ("=======================================\n") 18 | 19 | print ("============================== 使用方法 ==============================") 20 | print (" ") 21 | print ("- 1. 首先将图标文件手动放进每个文件夹中。") 22 | print ("- 2. 将 FolderIconTool 放置在希望批量替换文件夹图标的目录下。") 23 | print ("- 3. 运行本程序。") 24 | print (" ") 25 | print ("======================================================================\n") 26 | 27 | a = str(input('- 输入 1 开始设置图标:\n')) 28 | if (a == "1"): 29 | print("\n- 开始执行,请勿对文件进行操作。\n") 30 | start() 31 | else: 32 | b = str(input('按下回车键退出本程序\n')) 33 | exit() 34 | 35 | def start(): 36 | 37 | ## -----1. 检测当前目录下是否有 .ico 文件。----- 38 | 39 | iconame = [] 40 | print ("=======================================") 41 | print ("- 1. 检测当前目录下是否有 .ico 文件") 42 | print ("=======================================\n") 43 | DirPath = os.getcwd() ## DirPath:当前路径 44 | 45 | print ( "- 当前路径为:\n"+ DirPath) 46 | counter = 0 ## counter:计数 47 | 48 | print ( "- 该路径下的图标有:") 49 | for root, dirs, files in os.walk(DirPath, topdown=False): ## 遍历当前目录下的图标文件 50 | for file in files: 51 | if file.endswith(".ico"): 52 | print (os.path.join(root, file)) 53 | iconame.append(file) 54 | ## os.rename(root +"\\"+ file, root +"/"+"foldericon.ico") 55 | ## 早期做法:统一命名为 foldericon.ico 56 | counter += 1 57 | print ("\n- 检测完毕!") 58 | print ("- 该目录下共有 " + str(counter) + " 个图标文件。\n") 59 | 60 | 61 | ## 确认操作 62 | print ("=======================================") 63 | print ("- 是否开始将上述图标设为文件夹图标?") 64 | print ("=======================================") 65 | print ("(如果同一文件夹下有多个图标,将选取最后一个图标作为文件夹图标。)\n") 66 | a = str(input('- 输入 1 继续:\n')) 67 | 68 | if (a == "1"): 69 | 70 | print("\n- 开始批量设置,请勿对文件进行操作。\n") 71 | 72 | 73 | 74 | ## -----2. 将文件夹设置为只读。----- 75 | print ("=======================================") 76 | print ("- 2. 正在将文件夹设置为只读") 77 | print ("=======================================\n") 78 | ## 设置父文件夹只读 79 | for root, dirs, files in os.walk(DirPath, topdown=False): 80 | for file in files: 81 | if file.endswith(".ico"): 82 | os.chmod(root, stat.S_IREAD) ## 将带有 .ico 图标文件的目录设为只读。 83 | 84 | ## os.system("cd " + root + "&& attrib +r /d") 85 | ## 另一种设置方法,需要管理员权限。 86 | 87 | print ("- 已将「" + root + "」目录下所有子文件夹设置为只读(不包括文件)。") 88 | ## os.system("cd " + root + "&& attrib -r IconToolsBasic.py") 89 | 90 | print ("- 设置完成!\n") 91 | 92 | 93 | 94 | ## -----3. 新建一个 desktop.ini 文件,设为隐藏。----- 95 | print ("=======================================") 96 | print ("- 3. 正在新建 desktop.ini 文件") ## 将文件夹图标设置为同文件夹下的 iconfile.ico 图标(覆盖原内容) 97 | print ("=======================================\n") 98 | print ("- 正在获取 .ico 文件的文件名") 99 | print ("- 图标名称为:" + str(iconame)) 100 | print ("- 获取完毕!\n") 101 | 102 | ## 配置信息 103 | print ("- 正在生成 .ini 配置文件\n") 104 | iniline1 = "[.ShellClassInfo]" 105 | i = 0 106 | try: 107 | for root, dirs, files in os.walk(DirPath, topdown=False): 108 | for file in files: 109 | if file.endswith(".ico"): 110 | ## 为 desktop.ini 写入配置 111 | iniline2 = "IconResource=" + iconame[i] + ",0" 112 | i += 1 113 | iniline = iniline1 + "\n"+ iniline2 114 | 115 | try: 116 | os.system("cd " + root + "&& attrib -h -s desktop.ini") 117 | except FileNotFoundError: 118 | print ("正在为 " + file + " 新建配置信息。") 119 | except PersmissionError: 120 | print ("- 你没有对 " + file + " 进行配置的权限,请用管理员身份打开 FolderIconTool。") 121 | inifile = open(root + "\\" + "desktop.ini","w+") 122 | inifile.write(iniline) 123 | print ("正在为 " + file + " 更新配置信息。") 124 | inifile.close() 125 | os.system("cd " + root + "&& attrib +h desktop.ini") 126 | ## 将 desktop.ini 设为隐藏 127 | except: 128 | print('权限不足,请用管理员身份重新运行 IconTools') 129 | finally: 130 | print ("- 执行完毕!配置文件已隐藏。\n") 131 | print ("=======================================") 132 | print ("- 请检查图标是否已经替换成功,请按下回车键退出。") 133 | print ("- 如果尚未替换成功请输入 1 继续。") 134 | print ("=======================================\n") 135 | a = str(input("- 输入 1 继续,回车键退出:\n")) 136 | if (a == "1"): 137 | print ("=======================================") 138 | print ("- 是否强制刷新图标缓存?") 139 | print ("=======================================") 140 | print ("- 警告:该操作会关闭所有文件夹窗口,仅在图标未更新时使用!\n") 141 | a = str(input("- 输入 2 继续,回车键退出:\n")) 142 | if (a == "2"): 143 | print("\n- 正在关闭 Windows 外壳程序 Explorer") 144 | os.system("taskkill /f /im explorer.exe") 145 | print("- 正在清理「系统图标缓存数据库」") 146 | try: 147 | os.system("attrib -h -s -r \"%userprofile%\AppData\Local\IconCache.db\"") 148 | os.system("del /f \"%userprofile%\AppData\Local\IconCache.db\"") 149 | os.system("attrib /s /d -h -s -r \"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*\"") 150 | os.system("del /f \"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_32.db\"") 151 | os.system("del /f \"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_96.db\"") 152 | os.system("del /f \"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_102.db\"") 153 | os.system("del /f \"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_256.db\"") 154 | os.system("del /f \"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_1024.db\"") 155 | os.system("del /f \"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_idx.db\"") 156 | os.system("del /f \"%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_sr.db\"") 157 | except PersmissionError: 158 | print ("你没有足够的权限,请用管理员身份打开 FolderIconTool。") 159 | except WindowsError: 160 | print ("一部分缓存文件不存在,但这并不影响程序执行。") 161 | finally: 162 | print("- 正在清理「系统托盘记忆的图标」") 163 | try: 164 | os.system("echo y|reg delete \"HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify\" /v IconStreams") 165 | os.system("echo y|reg delete \"HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify\" /v PastIconsStream") 166 | except PersmissionError: 167 | print ("你没有足够的权限,请用管理员身份打开 FolderIconTool。") 168 | except WindowsError: 169 | print ("没有找到对应注册表,但这并不影响程序执行。") 170 | print("- 正在重启 Windows 外壳程序 Explorer") 171 | os.system("start explorer") 172 | print ("- 在 CMD 中运行可能会出现找不到文件的报错,但不影响正常刷新。") 173 | print ("(如果图标仍未刷新,请重启电脑。)\n") 174 | print ("- 执行完毕!") 175 | 176 | b = str(input('按下回车键退出本程序\n')) 177 | exit() 178 | 179 | else: 180 | b = str(input('按下回车键退出本程序\n')) 181 | exit() 182 | 183 | ## 开始执行 184 | 185 | main() 186 | 187 | ## 结束任务 188 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FolderIconTool README 2 | 3 | A little tool for Windows folder icon. 4 | 5 | ## How to use it 6 | 7 | 1. Put one icon in every folder, like this. 8 | 9 | ``` 10 | D:\ 11 | |- Common Documents 12 | |-|- Tools 13 | |-|-|- Tools.ico 14 | |-|- Pages 15 | |-|-|- Pages.ico 16 | |-|- Games 17 | |-|-|- Game Center.ico 18 | |-|- Movies 19 | |-|-|- Movie.ico 20 | ``` 21 | 22 | 2. Put FolderIconTool in the "Common Documents". 23 | 24 | 3. FolderIconTool will replace the every folders' icon. 25 | 26 | Enjoy it ! 27 | 28 | ![HowToUseFolderIconTool](imges/HowToUseFolderIconTool.gif) 29 | 30 | ## WARNING 31 | 32 | 1. FolderIconTool is secure, it only modifies the `.ini` configuration file. But on the safe side, you'd better try in the empty folder first before use it in the important folder. 33 | 34 | 2. If there are multiple `.ico` files in the same folder, FolderIconTool will automatically select the last icon as the folder icon. 35 | 36 | 3. If you refresh the icon cache in the last step and the icon is not changed, just restart the system. 37 | 38 | 39 | # FolderIconTool 中文说明 40 | 41 | 一个批量修改 Windows 文件夹图标的小工具。 42 | 43 | ## 使用方法 44 | 45 | 1. 你只需要把喜欢的图标放进各个文件夹中,就像这样—— 46 | 47 | ``` 48 | D:\ 49 | |- 常用文件 50 | |-|- 工具库 51 | |-|-|- Tools.ico 52 | |-|- 文档库 53 | |-|-|- Pages.ico 54 | |-|- 游戏库 55 | |-|-|- Game Center.ico 56 | |-|- 视频库 57 | |-|-|- Movie.ico 58 | ``` 59 | 60 | 2. 然后将 FolderIconTool 放在「常用文件」这个文件夹中。 61 | 62 | 3. 运行 FolderIconTool,就可以自动将该目录下的所有文件夹添加图标。 63 | 64 | ![HowToUseFolderIconTool](imges/HowToUseFolderIconTool.gif) 65 | 66 | ## 注意事项 67 | 68 | 1. 尽管 FolderIconTool 很安全,只会修改 `.ini` 配置文件,但在对重要文件夹设置图标之前。最好先在空文件夹中尝试一下,以免与预期不符。 69 | 70 | 2. 如果同一文件夹中有多个 `.ico` 文件,自动选取最后的图标作为文件夹图标。 71 | 72 | 3. 如果在最后一步刷新了图标缓存,图标依然没有更换,只需要重启系统即可。 73 | 74 | 4. 我生成了一个测试版的 `.exe`,但是目前很不稳定,如果电脑上有 python 3.5,建议使用 .py 直接运行。 75 | 76 | # Update log 77 | 78 | ## Nov 14, 2017 - Update FolderIconTool 0.0.6 79 | 80 | Add TestEnvironment , you can test FolderIconTool in the TestEnvironment. 81 | 82 | Fix some bug. 83 | 84 | ## Nov 13, 2017 - Update FolderIconTool 0.0.5 85 | 86 | Renamed as FolderIconTool. 87 | 88 | Add FolderIconTool.exe releases. 89 | 90 | ## Nov 13, 2017 - Update FolderIconTool 0.0.4 91 | 92 | Forced refresh function is added. 93 | 94 | Add more description. 95 | 96 | Fix some bug about System permission. 97 | 98 | ## Nov 9, 2017 - Update IconTool 0.0.3 99 | 100 | A version that can be used normally. 101 | 102 | Put `.ico` file in every folder, then start the IconTool.py. 103 | 104 | ## Nov 9, 2017 - Update IconTool 0.0.2 105 | 106 | Rebuild the IconTool. 107 | 108 | ## Oct 30, 2017 - Update IconTool 0.0.1 109 | 110 | The new project IconTool. 111 | -------------------------------------------------------------------------------- /TestEnvironment/Folder.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyunkkx/FolderIconTool/24734ec311bac22d69ed4fa936bed7130c88af68/TestEnvironment/Folder.ico -------------------------------------------------------------------------------- /TestEnvironment/FolderIconTool-TestEnvironment.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyunkkx/FolderIconTool/24734ec311bac22d69ed4fa936bed7130c88af68/TestEnvironment/FolderIconTool-TestEnvironment.rar -------------------------------------------------------------------------------- /TestEnvironment/书籍/iBooks Author.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyunkkx/FolderIconTool/24734ec311bac22d69ed4fa936bed7130c88af68/TestEnvironment/书籍/iBooks Author.ico -------------------------------------------------------------------------------- /TestEnvironment/游戏/Game Center.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyunkkx/FolderIconTool/24734ec311bac22d69ed4fa936bed7130c88af68/TestEnvironment/游戏/Game Center.ico -------------------------------------------------------------------------------- /TestEnvironment/软件/App Store.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyunkkx/FolderIconTool/24734ec311bac22d69ed4fa936bed7130c88af68/TestEnvironment/软件/App Store.ico -------------------------------------------------------------------------------- /TestEnvironment/音乐/iTunes.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyunkkx/FolderIconTool/24734ec311bac22d69ed4fa936bed7130c88af68/TestEnvironment/音乐/iTunes.ico -------------------------------------------------------------------------------- /imges/FolderIconTool.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyunkkx/FolderIconTool/24734ec311bac22d69ed4fa936bed7130c88af68/imges/FolderIconTool.ico -------------------------------------------------------------------------------- /imges/FolderIconTool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyunkkx/FolderIconTool/24734ec311bac22d69ed4fa936bed7130c88af68/imges/FolderIconTool.png -------------------------------------------------------------------------------- /imges/HowToUseFolderIconTool.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyunkkx/FolderIconTool/24734ec311bac22d69ed4fa936bed7130c88af68/imges/HowToUseFolderIconTool.gif --------------------------------------------------------------------------------