Times.2.moveFiles.pl
From Ball State University Libraries Wiki
Used for the Muncie Times collection.
Moves JPEGs and text files to their appropriate folders in preparation for upload.
The Script
#!/usr/bin/perl
#
$root = ".";
$dir = $root . "/load";
opendir(THEDIR, $dir) or die "Unable to open directory: $!";
@dirs = readdir THEDIR;
foreach $file (@dirs) {
if (-d "$dir/$file" && $file ne "." && $file ne "..") {
opendir(SUBDIR, "$dir/$file") or die "Unable to open directory: $!";
print("$file\n");
@files = readdir SUBDIR;
foreach $document (@files) {
if (-f "$dir/$file/$document" && $document =~ /(.*?)\.txt/) {
rename("$dir/$file/$document", "$dir/$file/transcripts/$document");
} elsif (-f "$dir/$file/$document" && $document =~ /(.*?)\.jpg/) {
rename("$dir/$file/$document", "$dir/$file/scans/$document");
} elsif (-f "$dir/$file/$document") {
print "Not JPEG or Text: $dir/$file/$document\n";
}
}
}
}
closedir THEDIR;
