Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

PerlbeginnercliAI generated

Directory Report

Build a Perl tool that gives you an overview of any folder on your computer: how many files of each type there are (by extension) and how much space they use, how files spread across size ranges (under 1 KB, 1 KB to 1 MB, and so on), and how many were last changed in each month. It walks through all the subfolders, skips what it can't read, and prints tidy tables, or saves the report as CSV. It's a good first Perl project: you'll learn walking folders with File::Find, reading file information with stat, hashes for counting and grouping, sorting, formatting output with printf, command-line options with Getopt::Long, and testing with Test::More.

Estimate
~6.5h
Steps
5
Completed by
0
Proposed by
codeseed.app

Perl core modules · File::Find · Getopt::Long · Text::CSV

Project roadmap

  1. 01

    Define the report

    ~1h

    Write README.md with the command (dirreport.pl FOLDER, with --top N, --csv FILE and --include-hidden) and an example of the three tables: by extension (count, total size and share), by size range, and by modification month. Decide how files without an extension are shown. Done when: README.md shows the options and example output.

  2. 02

    Walk the folder

    ~1.5h

    Use Getopt::Long for the options and check the folder exists. Walk it with File::Find, skipping symbolic links and hidden files unless asked, and for each file get its size and modification time with stat (or the -s file test). Count folders and files you couldn't read and continue. Done when: the tool prints the number of files and the total size, matching du on a test folder.

  3. 03

    Group the files

    ~1.5h

    Use hashes to count files and add up sizes by extension (lowercase), by size range, and by month (formatted as YYYY-MM with strftime from POSIX). Keep the grouping in separate subroutines that take a list of files, so they can be tested. Done when: the groups add up to the total number of files and bytes.

  4. 04

    Print the tables

    ~1h

    Print each table with printf in aligned columns, with sizes shown as B, KB, MB or GB. Sort extensions by total size (largest first) and show only the top N with an other line for the rest; list size ranges in order and months from newest to oldest. With --csv, write all three groupings to a CSV file with Text::CSV. Done when: the tables are aligned, and the CSV opens correctly in a spreadsheet.

  5. 05

    Test it

    ~1.5h

    Write tests with Test::More that create a temporary folder with files of set sizes and dates (using utime to change the dates), including a file without an extension and an unreadable folder, then check each grouping and the size formatting. Done when: prove -l t/ passes.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~6.5h · 5 steps

Tech stack

Perl core modulesFile::FindGetopt::LongText::CSV