Welcome to the File Organizer page.
This page contains a brief description and implementation instructions for the project.
Project Description
Automatically sorts files in a directory into folders by their file type/extension. For example, all .jpg
and .png
images go into an “Image” folder, documents into “Docs”, etc. This helps clean up directories by moving files based on a predefined mapping of extensions to folders.
Project Requirements
Python 3.x (built-in os
and pathlib
modules).
How to Run the Project
- Write a script (e.g.
organizer.py
) that scans the current folder usingos.scandir()
and sorts files into subfolders (creating them withos.makedirs()
as needed). - Place the script in the directory you want to organize, or modify it to point to a target directory.
- Run it:
python organizer.py
. The files will be moved to corresponding folders based on their extensions.
Key Concepts Learned
- File System Operations: Using
os
andpathlib
to navigate directories, check file extensions, make folders, and move/rename files. - Dictionaries and Loops: Mapping extensions to folder names (e.g. via a Python
dict
) and iterating over directory contents. - String Methods: Working with file suffixes (e.g.
suffix.lower()
). - Error Handling: Catching exceptions if folder already exists or file cannot be moved.
Possible Extensions
Extend mapping to more file types; handle nested subdirectories recursively; allow the user to specify categories at runtime; add a “dry run” mode that shows what would happen without moving files; implement a GUI file chooser.