Challenge

Problem

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.

Difficulty: Beginner

Instructions

  1. Recursively scan the specified directory for all files
  2. Collect metadata for each file: filename, full path, size (MB), modification date, file type (extension)
  3. Sort files by size (largest first)
  4. Generate CSV with headers: Filename,Path,Size_MB,Modified,Type
  5. Add summary statistics at the end:
    • Total files: X
    • Total size: Y.YY MB
    • File types: .txt (5), .jpg (3), .pdf (2)
  6. Output to 'file_inventory_YYYY-MM-DD.csv'

Files

Editable
Read-only

Hints

Hint 1

Find.find recursively traverses directories

Hint 2

File.size returns bytes, divide by 1048576.0 to get MB

Hint 3

File.mtime.strftime('%Y-%m-%d %H:%M:%S') formats the date

Hint 4

CSV.open(filename, 'w') creates a new CSV file

Hint 5

Use csv << [array] to write rows

Hint 6

Time.now.strftime('%Y-%m-%d') for today's date in filename

Hint 7

group_by with transform_values counts occurrences by type

Provided Files (Read-only)

1. Basic inventory - 3 files

Input:
generate_inventory('files')
Expected Output:
Generated inventory: file_inventory_2024-10-27.csv
Total files: 3
Total size: 1.50 MB

2. Single file inventory

Input:
generate_inventory('files')
Expected Output:
Generated inventory: file_inventory_2024-10-27.csv
Total files: 1
Total size: 0.00 MB

3. Multiple file types

Input:
generate_inventory('files')
Expected Output:
Generated inventory: file_inventory_2024-10-27.csv
Total files: 4
Total size: 1.50 MB
+ 2 hidden test cases