import os
import shutil
def sort_files(directory):
# Go through each file in the directory
for filename in [Link](directory):
# Create the full file path
filepath = [Link](directory, filename)
# Only sort files (skip directories)
if [Link](filepath):
# Get the file extension (e.g., 'txt' from '[Link]')
ext = [Link](filename)[1][1:].lower() # Remove the dot and lowercase
# Skip files with no extension
if ext:
# Create the folder name for the extension
target_folder = [Link](directory, ext)
# Make the folder if it doesn't exist
if not [Link](target_folder):
[Link](target_folder)
# Move the file into the extension folder
[Link](filepath, [Link](target_folder, filename))
print(f"Moved {filename} to folder: {ext}")
# Replace 'your_directory_path' with the directory you want to sort
sort_files('your_directory_path')