Organize your Pc folder using Python Automation script.
import os
import shutil
Function to organize files based on the first letter of their name
def organize_files_by_name(directory):
Get all files in the directory
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
Loop through each file
for file in files:
Get the first letter of the file name (case insensitive)
first_letter = file[0].upper()
Create a folder for the first letter if it doesn't exist
letter_folder = os.path.join(directory, first_letter)
if not os.path.exists(letter_folder):
os.makedirs(letter_folder)
shutil.move(os.path.join(directory, file), os.path.join(letter_folder, file))
print(f'Moved {file} to {letter_folder}')
directory = r'C:\path\to\your\directory'