import os
import shutil

def organize_files(directory):
    """
    Organizes files in the given directory into subfolders based on file extensions.
    """
    # Ensure the directory exists
    if not os.path.exists(directory):
        print(f"The directory {directory} does not exist.")
        return

    # Get all files in the directory
    files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]

    for file in files:
        # Get the file extension
        _, extension = os.path.splitext(file)
        extension = extension[1:]  # Remove the dot from the extension

        # Create a folder for the extension if it doesn't exist
        folder_path = os.path.join(directory, extension.capitalize())
        if not os.path.exists(folder_path):
            os.makedirs(folder_path)

        # Move the file to the folder
        shutil.move(
            os.path.join(directory, file),
            os.path.join(folder_path, file)
        )

    print(f"Organized {len(files)} files in {directory}.")
