Skip to content

Instantly share code, notes, and snippets.

@kirbyUK
Created January 24, 2016 15:04
Show Gist options
  • Save kirbyUK/677b8dcc4ec63d62ae98 to your computer and use it in GitHub Desktop.
Save kirbyUK/677b8dcc4ec63d62ae98 to your computer and use it in GitHub Desktop.
Rename Enron E-mail corpus to Windows-friendly filename
#!/usr/bin/perl -w
use File::Spec::Functions qw/catfile/;
use strict;
sub recurse
{
my $root = shift;
opendir my $dir, $root or die "Cannot open directory: '$root': $!\n";
for my $file(readdir $dir)
{
if((-d catfile($root, $file)) && ($file ne ".") && ($file ne ".."))
{
recurse(catfile($root, $file));
}
elsif((-f catfile($root, $file)) && ($file =~ /^\d+\.$/))
{
rename catfile($root, $file), catfile($root, $file . "txt");
}
}
}
if(-d $ARGV[0]) { recurse $ARGV[0] } else { die "Not a directory: '$ARGV[0]'\n" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment