Created
April 1, 2024 15:37
-
-
Save bellaabdelouahab/abcdb01424a3aa283ee950ed3def4157 to your computer and use it in GitHub Desktop.
Get rid of all icons names forever
This file contains 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 | |
import random | |
import unicodedata | |
# Define the unicode dictionary | |
unicode_dict = { | |
"char1": " ", | |
"char2": " ", | |
"char3": " ", | |
"char4": " ", | |
"char5": " ", | |
"char6": " ", | |
"char7": " ", | |
"char8": " ", | |
"char9": " ", | |
"char10": " ", | |
"char11": " ", | |
"char12": "" | |
} | |
# Get the path to the desktop | |
desktop_path = os.path.join(os.path.expanduser('~'), 'Desktop') | |
# Keep track of generated combinations | |
generated_combinations = set() | |
# Iterate over all files on the desktop | |
for filename in os.listdir(desktop_path): | |
print(filename) | |
# Create the full file path | |
file_path = os.path.join(desktop_path, filename) | |
# Skip directories | |
if os.path.isdir(file_path): | |
continue | |
new_filename = filename | |
# get a list of all json names not values | |
jsonnames = list(unicode_dict.keys()) | |
# get the file extension | |
fileextension = filename.split(".")[-1] | |
# add the random unicode character to the filename | |
while True: | |
# generate a 5 character combination | |
combination = ''.join(unicode_dict[random.choice(jsonnames)] for _ in range(5)) | |
# check if the combination has been generated before | |
if combination in generated_combinations: | |
continue | |
# add the combination to the set of generated combinations | |
generated_combinations.add(combination) | |
# create the new filename | |
new_filename = combination + "." + fileextension | |
new_file_path = os.path.join(desktop_path, new_filename) | |
# if the new filename does not exist, break the loop | |
if not os.path.exists(new_file_path): | |
break | |
# print the new filename | |
print(new_filename) | |
# Rename the file | |
os.rename(file_path, new_file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here is a script for anyone who is like me obsessed with clean desktop 😂