Requirements — File Organizer¶
What you will build and what you need before starting.
Learning Objectives¶
- Sort files into subdirectories based on extension using
mvandfind - Implement a
--dry-runflag that shows what would happen without doing it - Write structured log entries with timestamps
- Handle edge cases: duplicates, dotfiles, nested directories, no-extension files
- Use
casestatements to map extensions to categories
What You Will Build¶
file_organizer.sh — a script that takes a target directory, scans it for files, and moves them into category subdirectories:
Downloads/
├── Images/
│ ├── photo.jpg
│ └── screenshot.png
├── Documents/
│ ├── report.pdf
│ └── notes.txt
├── Videos/
│ └── lecture.mp4
├── Archives/
│ └── project.tar.gz
├── Code/
│ └── script.py
└── Other/
└── mystery_file
Prerequisites¶
| Skill | Where to review |
|---|---|
mv, mkdir -p |
Day 01 Part 2 — Files & Permissions |
for loops |
Day 04 Part 2 — Loops |
case statements |
Day 04 Part 1 — Control Flow |
| String manipulation | Week 02 Day 02 Part 2 |
| Functions | Week 02 Day 01 Part 1 |
| Logging pattern | 01-system-health-monitor/implementation |
Command-Line Interface¶
file_organizer.sh [OPTIONS] [TARGET_DIR]
Options:
-d, --dry-run Show what would be moved without actually moving
-l, --log FILE Write log to FILE (default: ./organizer.log)
-v, --verbose Print each action to stdout as well as the log
-h, --help Show this help
Arguments:
TARGET_DIR Directory to organize (default: current directory)
Categories and Extensions¶
| Category | Extensions |
|---|---|
| Images | jpg, jpeg, png, gif, bmp, svg, webp, ico, tiff |
| Documents | pdf, doc, docx, txt, md, odt, rtf, csv, xlsx, pptx |
| Videos | mp4, mkv, avi, mov, wmv, flv, webm |
| Audio | mp3, wav, flac, aac, ogg, m4a |
| Archives | zip, tar, gz, bz2, xz, 7z, rar, tgz |
| Code | sh, py, js, ts, go, rs, c, cpp, h, java, rb, php |
| Other | (anything not matched above) |
Acceptance Criteria¶
✓ Moves files into the correct category subdirectory
✓ --dry-run shows intended moves without executing them
✓ Writes a timestamped log entry for every file moved
✓ Skips subdirectories (only operates on files)
✓ Handles filenames with spaces correctly
✓ Does not overwrite existing files (appends _1, _2, etc.)
✓ Reports a summary: N files moved, N skipped, N already organised
✓ Returns exit code 0 on success, 1 if any move failed
Time Estimate¶
| Part | Time |
|---|---|
| Setup + scaffold | 15 min |
| Extension → category mapping | 20 min |
| Move logic with dedup | 25 min |
| Dry-run flag | 15 min |
| Logging + summary | 15 min |
| Testing | 20 min |
| Total | ~110 min |