Explore the full breakdown of pysorta.py, understand its flow, and contribute with confidence.
PySorta is a single-file script but uses clear modular logic. Here's the flat structure:
pysorta.py
README.md
deepdive.html
assets/
The script follows a clean top-to-bottom flow:
import os
import shutil
from datetime import datetime
from pathlib import Path
Why? These are standard Python libraries for working with file systems and timestamps.
FILE_CATEGORIES = {
"Images": [".jpg", ".jpeg", ".png"],
"Documents": [".pdf", ".docx", ".txt"],
"3D Models": [".obj", ".glb", ".fbx"]
}
This dictionary defines how files are grouped. Add more as needed!
folder = input("Enter folder path to organize: ").strip()
if not folder:
folder = os.getcwd()
If the user doesn’t enter a folder, it uses the current working directory.
print("Choose sorting method:")
print("1. By file type")
print("2. By date modified")
print("3. By file size")
choice = input("Enter your choice (1/2/3): ")
Simple CLI interface to choose sorting mode.
def sort_by_type(path):
for file in path.iterdir():
if file.is_file():
for category, extensions in FILE_CATEGORIES.items():
if file.suffix.lower() in extensions:
target_folder = path / category
target_folder.mkdir(exist_ok=True)
shutil.move(str(file), str(target_folder / file.name))
This is the core logic for organizing by type. The other two modes (date/size) use similar logic.
More clarity coming as I develop this walkthrough page, thanks for checking it out!