Skip to content

Instantly share code, notes, and snippets.

@n7st
Last active October 16, 2015 09:24
Show Gist options
  • Save n7st/5aef685fa2a80855fe2f to your computer and use it in GitHub Desktop.
Save n7st/5aef685fa2a80855fe2f to your computer and use it in GitHub Desktop.
Report albums in your music directory per year
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
# Dates to report between ($in 2000, $out 2015)
my ($in, $out);
my $output = './albums_per_year_output/';
Getopt::Long::GetOptions(
'in=i' => \$in,
'out=i' => \$out,
);
die 'Missing parameters.' if !$in || !$out;
mkdir $output if ! -d $output;
foreach ($in..$out) {
my $file_name = "$output$_.txt";
my $this_year = `find . -type d -name "*$_*"`;
if ($this_year) {
open (my $fh, '>', $file_name) or die "Could not write to $file_name.";
print $fh $this_year;
close $fh;
}
}
@n7st
Copy link
Author

n7st commented Oct 16, 2015

Requirements

  • Getopt::Long (CPAN)
  • Tested with Perl 5.20

Usage

cd /path/to/music/
perl /path/to/albumsbyyear.pl -in 2000 -out 2015
cd albums_per_year_output
cat *.txt

Output example

% cat 1975.txt
./Black Sabbath [UK]/(1975) Sabotage [320]
./Led Zeppelin [UK]/(1975) Physical Graffiti [LP] [V0]
./Pink Floyd [UK]/(1975) Wish You Were Here [LP] [MP3]
[...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment