Testing — File Organizer¶
Test the organizer thoroughly before running it on real directories.
Basic Smoke Test (Dry Run First)¶
Always run with --dry-run before the real thing:
Expected output:
[2024-01-15 09:00:00] [INFO ] === Starting organizer on /home/user/projects/file-organizer/test_sandbox (dry_run=true) ===
[2024-01-15 09:00:00] [INFO ] [DRY RUN] would move: .../test_sandbox/photo.jpg → .../test_sandbox/Images/photo.jpg
[2024-01-15 09:00:00] [INFO ] [DRY RUN] would move: .../test_sandbox/report.pdf → .../test_sandbox/Documents/report.pdf
...
[2024-01-15 09:00:00] [INFO ] === Done: moved=0 skipped=1 failed=0 ===
Done: moved=0 skipped=1 failed=0
The subdirectory subdir_to_skip should appear in the skipped count but NOT be moved.
Run the Real Move¶
[2024-01-15 09:00:01] [INFO ] moved: .../photo.jpg → .../Images/photo.jpg
[2024-01-15 09:00:01] [INFO ] moved: .../report.pdf → .../Documents/report.pdf
...
Done: moved=16 skipped=1 failed=0
Verify the result:
test_sandbox/.dotfile
test_sandbox/Archives/backup.tar.gz
test_sandbox/Archives/source.zip
test_sandbox/Audio/ambient.flac
test_sandbox/Audio/podcast.mp3
test_sandbox/Code/analysis.py
test_sandbox/Code/deploy.sh
test_sandbox/Code/index.js
test_sandbox/Documents/notes.txt
test_sandbox/Documents/readme.md
test_sandbox/Documents/report.pdf
test_sandbox/Documents/spreadsheet.csv
test_sandbox/Documents/file with spaces.txt
test_sandbox/Images/banner.svg
test_sandbox/Images/photo.jpg
test_sandbox/Images/screenshot.png
test_sandbox/Other/no_extension
test_sandbox/Videos/lecture.mp4
test_sandbox/Videos/tutorial.mkv
Test Deduplication¶
Create a duplicate and run again:
Check the result:
banner.svg photo.jpg photo_1.jpg screenshot.png
photo_1.jpg was created instead of overwriting photo.jpg.
Test Dotfile Skipping¶
-rw-r--r-- 1 user user 0 Jan 15 09:00 test_sandbox/.dotfile
Test Spaces in Filenames¶
test_sandbox/Documents/file with spaces.txt
If this fails, check that you used "$file" (quoted) and find -print0 with read -d ''.
Test the Log¶
[2024-01-15 09:00:00] [INFO ] === Starting organizer on ...
[2024-01-15 09:00:00] [INFO ] moved: .../photo.jpg → .../Images/photo.jpg
...
Test Error Handling¶
Error: '/no/such/dir' is not a directory
Exit: 1
# Read-only directory (simulate permission error)
mkdir -p /tmp/readonly_test
touch /tmp/readonly_test/file.txt
chmod 444 /tmp/readonly_test
bash file_organizer.sh /tmp/readonly_test
# Clean up
chmod 755 /tmp/readonly_test
rm -rf /tmp/readonly_test
Checklist¶
□ Dry-run shows actions without moving files
□ Files sorted into correct category directories
□ Duplicate filenames get _1, _2 suffix — no overwrites
□ Dotfiles skipped (stay in root)
□ Subdirectories not moved
□ Filenames with spaces handled correctly
□ Log file written with timestamps
□ Exit code 0 on success, 1 on any failure
□ shellcheck file_organizer.sh returns 0 warnings