From 517c1f54b66e55beb289a09e93ec365cbd05b99b Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Tue, 20 Mar 2018 18:13:50 -0500 Subject: [PATCH] Got dircopy and directory compare suboutine working --- file_processing/archive_statements.pl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/file_processing/archive_statements.pl b/file_processing/archive_statements.pl index 2455608..0e98b98 100755 --- a/file_processing/archive_statements.pl +++ b/file_processing/archive_statements.pl @@ -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 use File::Path qw(make_path remove_tree); #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 File::DirCompare; my $now = localtime; my $year = $now->year; @@ -23,8 +25,8 @@ print("Last year was $lastyear\n"); # Define and create folders my (%files1, %files2); -my $financial_folder = '~/Documents/financial/current_year'; -my $financial_archive_folder = '~/Documents/financial/1_financial_archives/'; +my $financial_folder = '/home/tracey/Documents/financial/current_year/'; +my $financial_archive_folder = '/home/tracey/Documents/financial/1_financial_archives/'; my $lastyear_folder = $financial_archive_folder . $lastyear . 'FinancialArchives'; my @folders = ( $financial_folder, $financial_archive_folder, $lastyear_folder ); @@ -47,18 +49,13 @@ my @curr_subdirs = $find_rule->directory->in( $financial_folder ); =end comment =cut - print("Copying current directories to archive folder\n"); print("From: $financial_folder\n"); print("To: $lastyear_folder\n"); - -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; +dircopy($financial_folder, $lastyear_folder) or die $!; # 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 @@ -78,3 +75,8 @@ sub compare_dirs { } # 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 +}