Got dircopy and directory compare suboutine working

This commit is contained in:
Tracey Clark 2018-03-20 18:13:50 -05:00
commit 517c1f54b6

View file

@ -9,8 +9,10 @@ use File::Find::Rule; # find all the subdirectories of a given directory
# http://search.cpan.org/~rclamp/File-Find-Rule-0.32/README # http://search.cpan.org/~rclamp/File-Find-Rule-0.32/README
use File::Path qw(make_path remove_tree); use File::Path qw(make_path remove_tree);
#use File::Copy; #use File::Copy;
use File::Copy::Recursive qw(fcopy rcopy dircopy fmove rmove dirmove); #use File::Copy::Recursive qw(fcopy rcopy dircopy fmove rmove dirmove);
use File::Copy::Recursive qw(dircopy);
use List::MoreUtils qw(uniq); use List::MoreUtils qw(uniq);
use File::DirCompare;
my $now = localtime; my $now = localtime;
my $year = $now->year; my $year = $now->year;
@ -23,8 +25,8 @@ print("Last year was $lastyear\n");
# Define and create folders # Define and create folders
my (%files1, %files2); my (%files1, %files2);
my $financial_folder = '~/Documents/financial/current_year'; my $financial_folder = '/home/tracey/Documents/financial/current_year/';
my $financial_archive_folder = '~/Documents/financial/1_financial_archives/'; my $financial_archive_folder = '/home/tracey/Documents/financial/1_financial_archives/';
my $lastyear_folder = $financial_archive_folder . $lastyear . 'FinancialArchives'; my $lastyear_folder = $financial_archive_folder . $lastyear . 'FinancialArchives';
my @folders = ( $financial_folder, $financial_archive_folder, $lastyear_folder ); my @folders = ( $financial_folder, $financial_archive_folder, $lastyear_folder );
@ -47,18 +49,13 @@ my @curr_subdirs = $find_rule->directory->in( $financial_folder );
=end comment =end comment
=cut =cut
print("Copying current directories to archive folder\n"); print("Copying current directories to archive folder\n");
print("From: $financial_folder\n"); print("From: $financial_folder\n");
print("To: $lastyear_folder\n"); print("To: $lastyear_folder\n");
dircopy($financial_folder, $lastyear_folder) or die $!;
system('cp -rp ' . $financial_folder . '/* ' . $lastyear_folder);
die("Can't launch cp: $!\n") if $? == -1;
die("cp killed by signal ".($? & 0x7F)."\n") if $? & 0x7F;
die("cp exited with error ".($? >> 8)."\n") if $? >> 8;
# Make sure contents match # Make sure contents match
#compare_dirs( $curr_subdir, $lastyear_folder ); compare_dirs( $financial_folder, $lastyear_folder );
# Delete all files from current year from archive folders # Delete all files from current year from archive folders
@ -78,3 +75,8 @@ sub compare_dirs {
} }
# Delete old directory # Delete old directory
sub delete_dirs {
# For all files in archive dir that are newer than last year delete them
# For all file in current folder that are older than this year delete them
}