mr crabs is awesome
@mrcrabsisawesom Tasks: 40
๐ ๏ธ 1 tool
๐ 87 karma
Enthusiast
Joined: September 2024
Follow
mr crabs is awesome's tools
-
3911685Released 1y ago100% FreeSure! Below is a Python script that automates file organization in your Downloads folder. The script categorizes files into subfolders based on their file extensions. For example, it will create folders for documents, images, audio, and video files. ```python import os import shutil # Define the path to the Downloads folder downloads_folder = os.path.expanduser("~/Downloads") # Define the file categories and their corresponding extensions file_categories = { 'Documents': ['.pdf', '.docx', '.doc', '.txt', '.pptx', '.ppt'], 'Images': ['.jpg', '.jpeg', '.png', '.gif', '.bmp'], 'Audio': ['.mp3', '.wav', '.aac', '.flac'], 'Video': ['.mp4', '.mov', '.avi', '.mkv'], 'Others': [] } # Create subfolders if they don't exist for category in file_categories.keys(): category_path = os.path.join(downloads_folder, category) if not os.path.exists(category_path): os.makedirs(category_path) # Organize files for filename in os.listdir(downloads_folder): file_path = os.path.join(downloads_folder, filename) # Skip if it's a directory if os.path.isdir(file_path): continue # Get file extension file_extension = os.path.splitext(filename)[1].lower() moved = False # Move file to the corresponding category folder for category, extensions in file_categories.items(): if file_extension in extensions: shutil.move(file_path, os.path.join(downloads_folder, category, filename)) moved = True break # If the file extension is not recognized, move it to 'Others' folder if not moved: shutil.move(file_path, os.path.join(downloads_folder, 'Others', filename)) print("Files have been organized!") ``` ### Instructions to Use the Script: 1. Install Python if you haven't already. 2. Save the code above in a file, e.g., `organize_downloads.py`. 3. Run the script using the command line: ``` python organize_downloads.py ``` This script will organize all the files in your Downloads folder by moving them into their respective folders. You can modify the `file_categories` variable to add or change categories and extensions as needed. Make sure to back up important files before running the script for the first time!