A messy Downloads folder with hundreds of unsorted files is a common problem. This drill teaches you to automatically organize files into categorized subdirectories based on their extensions. You'll learn file operations, directory creation, and how to handle naming conflicts when files already exist.
Use a hash to map categories to arrays of extensions: {'Images' => ['.jpg', '.png'], ...}
Dir.glob with File.file? filters out directories
File.extname returns the extension with the dot, use .downcase for case-insensitive matching
FileUtils.mkdir_p creates directories only if they don't exist
To handle duplicates, check File.exist? and append _1, _2, etc. to the basename
File.basename(path, ext) gives filename without extension
organize_downloads
Moved: report.pdf -> Documents/report.pdf Moved: song.mp3 -> Audio/song.mp3 Moved: vacation.jpg -> Images/vacation.jpg
organize_downloads
Moved: archive.zip -> Archives/archive.zip Moved: notes.txt -> Documents/notes.txt Moved: photo.png -> Images/photo.png Moved: video.mp4 -> Videos/video.mp4
organize_downloads
Moved: document.pdf -> Documents/document_1.pdf
Console output will appear here...
Are you sure?
You're making great progress