IT administrators, compliance teams, and migration planners need detailed file inventories before system changes. This drill teaches you to scan directory trees and generate CSV reports with comprehensive file metadata. You'll learn file metadata extraction using a metadata file (simulating real file stats), data aggregation, and report formatting. Note: This drill parses CSV manually using string methods rather than Ruby's CSV library.
Load metadata with JSON.parse(File.read('files/metadata.json'))
Use metadata.map to iterate over each file path and its info
Calculate MB: (info['size_bytes'] / 1048576.0).round(2)
Build CSV manually: lines << "#{val1},#{val2},#{val3}"
Sort descending by size: sort_by! { |f| -f[:size_mb] }
Group by type with: group_by { |f| f[:type] }.transform_values(&:count)
csv = generate_inventory puts csv.lines.first.strip
Total files: 4 Total size: 0.90 MB File types: .pdf (1), .jpg (1), .csv (1), .txt (1) Filename,Path,Size_MB,Modified,Type
csv = generate_inventory
data_lines = csv.lines[1..4]
puts data_lines.map { |l| l.split(',')[0] }.join(', ')
Total files: 4 Total size: 0.90 MB File types: .pdf (1), .jpg (1), .csv (1), .txt (1) report.pdf, photo.jpg, data.csv, notes.txt
generate_inventory
Total files: 4 Total size: 0.90 MB File types: .pdf (1), .jpg (1), .csv (1), .txt (1)
Console output will appear here...
Are you sure?
You're making great progress
Become a Ruby Pro
1,600+ problems to master every concept