#!/usr/bin/perl

# Remove all spaces in filenames in selected directory and all of its subdirectories.

use utf8;
use strict;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");

use File::Find;

my @directories = glob "datasets/*/*/*";
my @foundfiles;

# Here, we collect all .mp3 files below each directory in @directories and put them
# into @foundfiles
find( sub { push @foundfiles, $File::Find::name if /\w+ \w+\.\w+$/ }, @directories );

foreach my $newf (@foundfiles) {
    # print "$newf\n";
    $newf =~ s/(\w+) +(\w+\.\w+)$/$1$2/;
    # print "$newf\n";
}

# and output them all
# print join("\n",@foundfiles), "\n";