shell-scripts/file_processing/archive_statements.pl
2023-09-11 17:21:56 -05:00

35 lines
1.3 KiB
Perl
Executable file

#!/usr/bin/perl
use Modern::Perl;
use ProcessDirectories;
# Script to archive the financial data from the previous year
use Carp qw( croak );
# use File::Basename;
# use File::Find::Rule;
# use File::Copy::Recursive qw(dircopy);
# use File::DirCompare;
# use Getopt::Long qw(GetOptionsFromArray);
use Time::Piece qw/localtime/;
my $now = localtime;
my $year = $now->year;
my $lastyear = $now->add_years(-1)->year;
print("Current year: $year Last year: $lastyear\n");
# Define and create folders
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';
create_archive_dirs ( $financial_folder, $lastyear_folder );
# Make sure contents match before we do any deleting
# croak on errors to guard against data loss
# my $same_result = compare_dirs( $financial_folder, $lastyear_folder );
croak "Error: The source and destintion folder contents are not the same!" unless ( compare_dirs( $financial_folder, $lastyear_folder ) );
# Delete all files from current year from archive folders
# Also delete files from last year in current year folder
clean_dirs( $financial_folder, $lastyear_folder, $year, $lastyear );