Created
January 6, 2024 15:24
-
-
Save eyaler/2ad37a7edd04f1a4ce339047ce5feabd to your computer and use it in GitHub Desktop.
Find Windows folders with a fake display name and optionally delete offending desktop*.ini files to reset folder name and behavior
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
"""Find Windows folders with a fake display name and optionally delete offending desktop*.ini files to reset folder name and behavior | |
Usage: python unlocalize.py [delete] | |
Renaming a folder via Windows 7-11 Explorer search results, might not change the actual folder name, but just the displayed name in Explorer. | |
The fake display name is set as a LocalizedResourceName in desktop.ini, and the effect survives even if renaming desktop.ini itself. | |
Moreover, from this point on any further renaming via Explorer, even not in search results, will only affect the displayed name. | |
This can lead to data loss e.g. copying a folder with the old name to the same location, unintentionally overwriting the "renamed" folder. | |
See also: https://superuser.com/questions/1777997/prevent-windows-explorer-to-use-localizedresourcename-when-renaming-file-or-fo | |
""" | |
import glob | |
import os | |
import re | |
import sys | |
import win32api | |
delete = False # True will try to delete offending desktop*.ini files in folders with a set LocalizedResourceName | |
limit_to_locations = [] # Leave empty to find all folders on all drives, or list base locations to scan | |
if len(sys.argv) > 1 and sys.argv[1].endswith('delete'): | |
delete = True | |
for base in limit_to_locations or win32api.GetLogicalDriveStrings().split('\0')[:-1]: | |
for file in glob.iglob(os.path.join(base, r'\**\desktop*.ini'), recursive=True): | |
with open(file, encoding='utf8', errors='backslashreplace') as f: | |
match = re.search(r'LocalizedResourceName=((?:.(?!\.dll))*)$', f.read(), re.M) | |
if match: | |
print(file, match[1]) | |
if delete: | |
try: | |
os.remove(file) | |
except PermissionError as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment