Menu

Post image 1
Post image 2
1 / 2
0

Automate File Organization: Python Script That Sorts 1000 Files in Seconds

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

Automate File Organization: Python Script That Sorts 1000 Files in Seconds If you're like most developers, your Downloads folder is a disaster. PDFs mixed with images, zip files, code snippets — everything jumbled together. Here's a Python script that automatically organizes files by type, date, or custom rules. The Basic File Sorter import os import shutil from pathlib import Path from datetime import datetime def organize_files ( source_dir : str , dry_run : bool = True ): """ Sort files into category folders automatically. """ file_categories = { ' Images ' : [ ' .jpg ' , ' .jpeg ' , ' .png ' , ' .gif ' , ' .bmp ' , ' .svg ' , ' .webp ' ], ' Documents ' : [ ' .pdf ' , ' .doc ' , ' .docx ' , ' .txt ' , ' .odt ' , ' .rtf ' ], ' Spreadsheets ' : [ ' .xls ' , ' .xlsx ' , ' .csv ' , ' .ods ' ], ' Code ' : [ ' .py ' , ' .js ' , ' .html ' , ' .css ' , ' .java ' , ' .cpp ' , ' .go ' ], ' Archives ' : [ ' .zip ' , ' .tar ' , ' .gz ' , ' .rar ' , ' .7z ' ], ' Videos ' : [ ' .mp4 ' , ' .avi ' , ' .mkv ' , ' .mov ' ,…

Continue reading — create a free account

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

Read More