Tips_and_Hacks/MAST_tW_PDF_Updater/FilesForUpdates/Convert_OHSB_to_MAST_HB.bad.pl

103 lines
2.1 KiB
Perl

#!/usr/bin/perl
use warnings;
use strict;
use autodie;
use File::Copy;
my %filenames;
while (<DATA>) {
chomp;
if (/([^\t]*)\t([^\t]*)/) {
#($oldName, $newName) = ($1, $2);
$filenames{$1} = $2;
}
}
# capture script name, in case we are running the script from the
# same directory we working on.
my $this_file = (split(/\//, $0))[-1];
print "skipping file: $this_file\n";
my $oldnames = "/home/henry/Documents/WA_Repo/OSHB";
my $newnames = "/home/henry/Documents/WA_Repo/MAST_HB";
# open the directory
opendir(my $dh, $oldnames);
# grep out all directories and possibly this script.
my @files_to_rename = grep { !-d && $_ ne $this_file } readdir $dh;
closedir $dh;
### UPDATED ###
# create hash of file names from lists:
my @missing_new_file = ();
# change directory, so we don't have to worry about pathing
# of files to rename and move...
chdir($oldnames);
mkdir($newnames) if !-e $newnames;
### UPDATED ###
for my $file (@files_to_rename) {
# Check that current file exists in the hash,
# if true, copy old file to new location with new name
if( exists($filenames->{$file}) ) {
copy($file, "$newnames/$filenames->{$file}");
} else {
push @missing_new_file, $file;
}
}
if( @missing_new_file ) {
print "Could not map files:\n",
join("\n", @missing_new_file), "\n";
}
__DATA__
Gen.xml 01-GEN.xml
Exod.xml 02-EXO.xml
Lev.xml 03-LEV.xml
Num.xml 04-NUM.xml
Deut.xml 05-DEU.xml
Josh.xml 06-JOS.xml
Judg.xml 07-JDG.xml
Ruth.xml 08-RUT.xml
1Sam.xml 09-1SA.xml
2Sam.xml 10-2SA.xml
1Kgs.xml 11-1KI.xml
2Kgs.xml 12-2KI.xml
1Chr.xml 13-1CH.xml
2Chr.xml 14-2CH.xml
Ezra.xml 15-EZR.xml
Neh.xml 16-NEH.xml
Esth.xml 17-EST.xml
Job.xml 18-JOB.xml
Ps.xml 19-PSA.xml
Prov.xml 20-PRO.xml
Eccl.xml 21-ECC.xml
Song.xml 22-SNG.xml
Isa.xml 23-ISA.xml
Jer.xml 24-JER.xml
Lam.xml 25-LAM.xml
Ezek.xml 26-EZK.xml
Dan.xml 27-DAN.xml
Hos.xml 28-HOS.xml
Joel.xml 29-JOL.xml
Amos.xml 30-AMO.xml
Obad.xml 31-OBA.xml
Jonah.xml 32-JON.xml
Mic.xml 33-MIC.xml
Nah.xml 34-NAM.xml
Hab.xml 35-HAB.xml
Zeph.xml 36-ZEP.xml
Hag.xml 37-HAG.xml
Zech.xml 38-ZEC.xml
Mal.xml 39-MAL.xml