├── clean.py ├── cleaner.bend ├── cleanstuff.cmd └── readme.md /clean.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | # Define the path to the current directory 5 | desktop_path = os.getcwd() # Use current working directory 6 | 7 | # Categories and their corresponding folder names 8 | categories = { 9 | '.txt': 'Documents', '.docx': 'Documents', '.pdf': 'PDFs', '.doc': 'Documents', 10 | '.rtf': 'Documents', '.odt': 'Documents', 11 | '.jpg': 'Images', '.jpeg': 'Images', '.png': 'Images', '.gif': 'Images', 12 | '.bmp': 'Images', '.tiff': 'Images', '.ico': 'Images', '.svg': 'Images', 13 | '.psd': 'Images', '.ai': 'Images', 14 | '.mp4': 'Videos', '.avi': 'Videos', '.mov': 'Videos', '.wmv': 'Videos', 15 | '.mkv': 'Videos', '.flv': 'Videos', '.m4v': 'Videos', '.webm': 'Videos', 16 | '.3gp': 'Videos', '.mpg': 'Videos', '.mpeg': 'Videos', '.ts': 'Videos', '.vob': 'Videos', 17 | '.xls': 'Spreadsheets', '.xlsx': 'Spreadsheets', '.csv': 'Data', 18 | '.exe': 'Executables', '.bat': 'Executables', '.sh': 'Executables', '.jar': 'Executables', 19 | '.vcf': 'Contacts', 20 | '.ppt': 'Presentations', '.pptx': 'Presentations', '.key': 'Presentations', '.odp': 'Presentations', 21 | '.mp3': 'Audio', '.wav': 'Audio', '.aac': 'Audio', '.ogg': 'Audio', '.flac': 'Audio', 22 | '.zip': 'Archives', '.rar': 'Archives', '.7z': 'Archives', '.tar': 'Archives', '.gz': 'Archives' 23 | } 24 | 25 | # Determine which folders are needed 26 | needed_folders = set() 27 | for filename in os.listdir(desktop_path): 28 | file_path = os.path.join(desktop_path, filename) 29 | if os.path.isfile(file_path): 30 | file_ext = os.path.splitext(filename)[1].lower() # Ensure case insensitivity 31 | folder_name = categories.get(file_ext) 32 | if folder_name: 33 | needed_folders.add(folder_name) 34 | 35 | # Create only the needed folders 36 | for folder in needed_folders: 37 | folder_path = os.path.join(desktop_path, folder) 38 | if not os.path.exists(folder_path): 39 | os.makedirs(folder_path) 40 | 41 | # Move files into corresponding folders 42 | for filename in os.listdir(desktop_path): 43 | file_path = os.path.join(desktop_path, filename) 44 | if os.path.isfile(file_path): 45 | file_ext = os.path.splitext(filename)[1].lower() # Ensure case insensitivity 46 | folder_name = categories.get(file_ext) 47 | if folder_name: 48 | shutil.move(file_path, os.path.join(desktop_path, folder_name, filename)) 49 | 50 | print("Desktop cleaned!") 51 | -------------------------------------------------------------------------------- /cleaner.bend: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // Define the directory path 3 | let desktop_path = os::getcwd(); 4 | 5 | // Map of file extensions to folder names 6 | let extension_map = { 7 | ".txt": "Documents", 8 | ".docx": "Documents", 9 | ".pdf": "PDFs", 10 | ".doc": "Documents", 11 | ".rtf": "Documents", 12 | ".odt": "Documents", 13 | ".jpg": "Images", 14 | ".jpeg": "Images", 15 | ".png": "Images", 16 | ".gif": "Images", 17 | ".bmp": "Images", 18 | ".tiff": "Images", 19 | ".ico": "Images", 20 | ".svg": "Images", 21 | ".psd": "Images", 22 | ".ai": "Images", 23 | ".mp4": "Videos", 24 | ".avi": "Videos", 25 | ".mov": "Videos", 26 | ".wmv": "Videos", 27 | ".mkv": "Videos", 28 | ".flv": "Videos", 29 | ".m4v": "Videos", 30 | ".webm": "Videos", 31 | ".3gp": "Videos", 32 | ".mpg": "Videos", 33 | ".mpeg": "Videos", 34 | ".ts": "Videos", 35 | ".vob": "Videos", 36 | ".xls": "Spreadsheets", 37 | ".xlsx": "Spreadsheets", 38 | ".csv": "Data", 39 | ".exe": "Executables", 40 | ".bat": "Executables", 41 | ".sh": "Executables", 42 | ".jar": "Executables", 43 | ".vcf": "Contacts", 44 | ".ppt": "Presentations", 45 | ".pptx": "Presentations", 46 | ".key": "Presentations", 47 | ".odp": "Presentations", 48 | ".mp3": "Audio", 49 | ".wav": "Audio", 50 | ".aac": "Audio", 51 | ".ogg": "Audio", 52 | ".flac": "Audio", 53 | ".zip": "Archives", 54 | ".rar": "Archives", 55 | ".7z": "Archives", 56 | ".tar": "Archives", 57 | ".gz": "Archives" 58 | }; 59 | 60 | // Loop through all files in the directory 61 | for path in fs::read_dir(&desktop_path) { 62 | if path.is_file() { 63 | let ext = path.extension().unwrap_or(""); 64 | if extension_map.contains_key(ext) { 65 | let folder = extension_map[ext]; 66 | let folder_path = desktop_path.join(folder); 67 | if !folder_path.exists() { 68 | fs::create_dir(&folder_path); 69 | } 70 | fs::move(&path, folder_path.join(path.file_name().unwrap())); 71 | } 72 | } 73 | } 74 | 75 | println("Desktop cleaned!"); 76 | } 77 | -------------------------------------------------------------------------------- /cleanstuff.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enabledelayedexpansion 3 | 4 | rem Define the directory path 5 | set "desktop_path=%cd%" 6 | 7 | rem Loop through all files in the directory 8 | for %%f in ("%desktop_path%\*.*") do ( 9 | rem Extract file extension 10 | set "ext=%%~xf" 11 | rem Determine folder name based on extension 12 | set "folder=" 13 | if "!ext!"==".txt" set "folder=Documents" 14 | if "!ext!"==".docx" set "folder=Documents" 15 | if "!ext!"==".pdf" set "folder=PDFs" 16 | if "!ext!"==".doc" set "folder=Documents" 17 | if "!ext!"==".rtf" set "folder=Documents" 18 | if "!ext!"==".odt" set "folder=Documents" 19 | if "!ext!"==".jpg" set "folder=Images" 20 | if "!ext!"==".jpeg" set "folder=Images" 21 | if "!ext!"==".png" set "folder=Images" 22 | if "!ext!"==".gif" set "folder=Images" 23 | if "!ext!"==".bmp" set "folder=Images" 24 | if "!ext!"==".tiff" set "folder=Images" 25 | if "!ext!"==".ico" set "folder=Images" 26 | if "!ext!"==".svg" set "folder=Images" 27 | if "!ext!"==".psd" set "folder=Images" 28 | if "!ext!"==".ai" set "folder=Images" 29 | if "!ext!"==".mp4" set "folder=Videos" 30 | if "!ext!"==".avi" set "folder=Videos" 31 | if "!ext!"==".mov" set "folder=Videos" 32 | if "!ext!"==".wmv" set "folder=Videos" 33 | if "!ext!"==".mkv" set "folder=Videos" 34 | if "!ext!"==".flv" set "folder=Videos" 35 | if "!ext!"==".m4v" set "folder=Videos" 36 | if "!ext!"==".webm" set "folder=Videos" 37 | if "!ext!"==".3gp" set "folder=Videos" 38 | if "!ext!"==".mpg" set "folder=Videos" 39 | if "!ext!"==".mpeg" set "folder=Videos" 40 | if "!ext!"==".ts" set "folder=Videos" 41 | if "!ext!"==".vob" set "folder=Videos" 42 | if "!ext!"==".xls" set "folder=Spreadsheets" 43 | if "!ext!"==".xlsx" set "folder=Spreadsheets" 44 | if "!ext!"==".csv" set "folder=Data" 45 | if "!ext!"==".exe" set "folder=Executables" 46 | if "!ext!"==".bat" set "folder=Executables" 47 | if "!ext!"==".sh" set "folder=Executables" 48 | if "!ext!"==".jar" set "folder=Executables" 49 | if "!ext!"==".vcf" set "folder=Contacts" 50 | if "!ext!"==".ppt" set "folder=Presentations" 51 | if "!ext!"==".pptx" set "folder=Presentations" 52 | if "!ext!"==".key" set "folder=Presentations" 53 | if "!ext!"==".odp" set "folder=Presentations" 54 | if "!ext!"==".mp3" set "folder=Audio" 55 | if "!ext!"==".wav" set "folder=Audio" 56 | if "!ext!"==".aac" set "folder=Audio" 57 | if "!ext!"==".ogg" set "folder=Audio" 58 | if "!ext!"==".flac" set "folder=Audio" 59 | if "!ext!"==".zip" set "folder=Archives" 60 | if "!ext!"==".rar" set "folder=Archives" 61 | if "!ext!"==".7z" set "folder=Archives" 62 | if "!ext!"==".tar" set "folder=Archives" 63 | if "!ext!"==".gz" set "folder=Archives" 64 | 65 | rem If a folder name was determined, move the file 66 | if not "!folder!"=="" ( 67 | if not exist "%desktop_path%\!folder!" mkdir "%desktop_path%\!folder!" 68 | move "%%f" "%desktop_path%\!folder!\%%~nxf" 69 | ) 70 | ) 71 | 72 | echo Desktop cleaned! 73 | endlocal 74 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Desktop Cleaner Script 2 | 3 | ## Overview 4 | The Desktop Cleaner Script is a utility for organizing files in a directory into specific folders based on their file extensions. This helps in maintaining a neat and organized directory, whether it's your desktop or any specific folder that needs cleaning. The script is available in three versions: Python, Bash, and Windows CMD file. 5 | 6 | ## Features 7 | - **Support for Multiple File Types:** Organizes a wide range of file types including documents, images, videos, spreadsheets, presentations, audio files, and more. 8 | - **Automatic Folder Creation:** Automatically creates folders if they don't already exist. 9 | - **Platform-Specific Scripts:** Available for Windows (CMD), Linux, and macOS (Bash), and universally (Python). 10 | 11 | ## Prerequisites 12 | Before running the scripts, ensure you have the necessary environment set up: 13 | - **Python:** Python must be installed for the Python script. [Download Python](https://www.python.org/downloads/) 14 | - **Bash:** Default on Linux and macOS systems. 15 | - **Windows Command Prompt:** For running CMD scripts on Windows. 16 | 17 | ## Installation 18 | 19 | ### Cloning the Repository 20 | To get started with these scripts, clone the repository to your local machine using: 21 | ```bash 22 | git clone https://github.com/RohanHandore/Desktop-Cleaner-Script.git 23 | cd desktop-cleaner 24 | ``` 25 | 26 | ### Adding Scripts to PATH (Windows) 27 | To run the CMD script from any directory: 28 | 1. Right-click on 'This PC' or 'Computer' on your desktop or in File Explorer. 29 | 2. Select 'Properties'. 30 | 3. Click on 'Advanced system settings'. 31 | 4. In the System Properties window, click on the 'Environment Variables' button. 32 | 5. In the Environment Variables window, find the 'Path' variable in the 'System variables' section and click 'Edit'. 33 | 6. In the Edit Environment Variable window, click 'New' and add the path to the folder where your `clean.cmd` script is located. 34 | 7. Click 'OK' on all dialogs to close them and apply the changes. 35 | 36 | ## Usage 37 | 38 | ### Python Script 39 | 1. Navigate to the script directory. 40 | 2. Run the script using: 41 | ```bash 42 | python clean.py 43 | ``` 44 | This will organize the current directory. 45 | 46 | ### Bash Script 47 | 1. Ensure the script is executable: 48 | ```bash 49 | chmod +x clean.sh 50 | ``` 51 | 2. Run the script: 52 | ```bash 53 | ./clean.sh 54 | ``` 55 | This executes the script in the current directory. 56 | 57 | ### CMD Script 58 | 1. Run the script in CMD: 59 | ```cmd 60 | clean.cmd 61 | ``` 62 | This will organize files in the current directory on Windows. 63 | 64 | ## File Extensions Handled 65 | The script categorizes and moves files based on the following extensions: 66 | - **Documents:** `.txt`, `.docx`, `.pdf`, `.doc`, `.rtf`, `.odt` 67 | - **Images:** `.jpg`, `.jpeg`, `.png`, `.gif`, `.bmp`, `.tiff`, `.ico`, `.svg`, `.psd`, `.ai` 68 | - **Videos:** `.mp4`, `.avi`, `.mov`, `.wmv`, `.mkv`, `.flv`, `.m4v`, `.webm`, `.3gp`, `.mpg`, `.mpeg`, `.ts`, `.vob` 69 | - **Spreadsheets:** `.xls`, `.xlsx`, `.csv` 70 | - **Executables:** `.exe`, `.cmd`, `.sh`, `.jar` 71 | - **Contacts:** `.vcf` 72 | - **Presentations:** `.ppt`, `.pptx`, `.key`, `.odp` 73 | - **Audio:** `.mp3`, `.wav`, `.aac`, `.ogg`, `.flac` 74 | - **Archives:** `.zip`, `.rar`, `.7z`, `.tar`, `.gz` 75 | 76 | ### Bend 77 | 1. **Run the below command in the terminal if you have bend setup:** 78 | ```bash 79 | bend run cleaner.bend 80 | ``` 81 | --------------------------------------------------------------------------------