Menu

Post image 1
Post image 2
1 / 2
0

Python File Organization Script: Auto-Sort Downloads Folder

DEV Community·Brad·18 days ago
#cq55d05u
Reading 0:00
15s threshold

Python File Organization Script: Auto-Sort Downloads Folder If your Downloads folder looks like digital chaos, Python can automate the cleanup in seconds. The Solution import os import shutil from pathlib import Path from datetime import datetime FILE_TYPES = { ' Images ' : [ ' .jpg ' , ' .jpeg ' , ' .png ' , ' .gif ' , ' .bmp ' , ' .svg ' , ' .webp ' ], ' Documents ' : [ ' .pdf ' , ' .doc ' , ' .docx ' , ' .txt ' , ' .xlsx ' , ' .pptx ' ], ' Videos ' : [ ' .mp4 ' , ' .avi ' , ' .mkv ' , ' .mov ' , ' .wmv ' ], ' Audio ' : [ ' .mp3 ' , ' .wav ' , ' .flac ' , ' .aac ' , ' .ogg ' ], ' Archives ' : [ ' .zip ' , ' .rar ' , ' .7z ' , ' .tar ' , ' .gz ' ], ' Code ' : [ ' .py ' , ' .js ' , ' .html ' , ' .css ' , ' .java ' , ' .json ' ], } def organize_folder ( folder_path : str , dry_run : bool = True ): folder = Path ( folder_path ) moved = [] for file_path in folder . iterdir (): if file_path . is_dir (): continue ext = file_path . suffix . lower () category = ' Other ' for cat , extensions in FILE_TYPES .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More