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: names, paths, sizes, modification dates, and types. You'll learn CSV generation, file metadata extraction, data aggregation, and report formatting.
Find.find recursively traverses directories
File.size returns bytes, divide by 1048576.0 to get MB
File.mtime.strftime('%Y-%m-%d %H:%M:%S') formats the date
CSV.open(filename, 'w') creates a new CSV file
Use csv << [array] to write rows
Time.now.strftime('%Y-%m-%d') for today's date in filename
group_by with transform_values counts occurrences by type
generate_inventory('files')
Generated inventory: file_inventory_2024-10-27.csv Total files: 3 Total size: 1.50 MB
generate_inventory('files')
Generated inventory: file_inventory_2024-10-27.csv Total files: 1 Total size: 0.00 MB
generate_inventory('files')
Generated inventory: file_inventory_2024-10-27.csv Total files: 4 Total size: 1.50 MB
Console output will appear here...
Are you sure?
You're making great progress