Created
January 24, 2016 15:04
-
-
Save kirbyUK/677b8dcc4ec63d62ae98 to your computer and use it in GitHub Desktop.
Rename Enron E-mail corpus to Windows-friendly filename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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