ACTION=MbxGet,DEST_OR_SRC_SVR=WPSP,IN_MBX=/DWH/Upload,FILE_LIST=test_ftp_wpsp.lst, LOCAL_DIR=/datax/srv/dwh/outbound,FILE_TYPE=ASCII#$FILE_PATTERN=test_ftp_wpsp.txt
I would need to create a parameter ZIP='Y' in the current Perl script, and call a subroutine "Zip" that is already created in an old script.
Here is what I have so far:
#new params added to control record
GMIoutl::Zip($params{ZIP});
#If the control record states ZIP='Y', then zip the file.
if ($params{ZIP} = "Y" {
&Zip;
}
#Subroutine from Perl Module: GMIoutl.pm
sub Zip
{
my $self = FormatSelf(@_);
my $func_exit = 0;
my $badcnt;
my $numfiles;
if (!defined $self->{SourceDir})
{
print "Could not determine source file directory <$self->{SourceDir}>\n";
return 1;
}
if (!defined $self->{InputFileName})
{
print "Could not determine source file name <$self->{InputFileName}>\n";
return 1;
}
if (!defined $self->{DestDir})
{
print "Could not determine destination file directory <$self->{DestDir}>\n";
return 1;
}
if (!defined $self->{OutputFileName})
{
print "Could not determine destination/target file name <$self->{OutputFileName}>\n";
return 1;
}
print "SourceDir = $self->{SourceDir} \n";
print "DestDir = $self->{DestDir} \n";
print "Wild card InputFileName/Single Filename = $self->{InputFileName} \n";
print "OutputFileName = $self->{OutputFileName} \n";
#********************************************************************
#* Open the directory which contains the files to be zip/compressed *
#********************************************************************
opendir(CMDDIR, "$self->{SourceDir}") || $badcnt++;
if ($badcnt > 0)
{
print "ERROR: Cannot open <$self->{SourceDir}> directory for processing. \n";
return 1;
}
else
{
#****************************************************************************
#* Read the files containing the search string in the directory into a list *
#****************************************************************************
@cf = readdir(CMDDIR);
foreach (@cf)
{
if (/$self->{InputFileName}/)
{
#create an array containing the desired filenames
push(@FILES,$_);
}
}
$numfiles = @FILES;
print "INFO: Number of files to be ZIP'ed/Compressed are $numfiles \n\n";
closedir(CMDDIR);
if ($numfiles == 0)
{
#**************************************
#* There are no files to zip/compress *
#**************************************
print "ERROR: No files in <$self->{SourceDir}> directory to zip. \n";
return 1;
}
else
{
if (-e "$self->{DestDir}/$self->{OutputFileName}.zip")
{
print("INFO: <$self->{OutputFileName}.zip> file is FOUND in <$self->{DestDir}> directory. \n");
print("INFO: Deleting <$self->{OutputFileName}.zip> file from <$self->{DestDir}> directory. \n\n");
$func_exit = system ("rm -f $self->{DestDir}/$self->{OutputFileName}.zip");
if ($func_exit)
{
print("ERROR: Unable to delete <$self->{OutputFileName}.zip> file from <$self->{DestDir}> directory. \n");
return 1;
}
}
print("INFO: Creating a new <$self->{OutputFileName}.zip> file in <$self->{DestDir}> directory. \n");
foreach (@FILES)
{
$func_exit = system ("zip -j $self->{DestDir}/$self->{OutputFileName}.zip $self->{SourceDir}/$_");
if ($func_exit)
{
print("ERROR: Unable to zip/compress <$_> file into <$self->{OutputFileName}.zip> file. \n");
return 1;
}
}
}
}
if (!$self->Silent())
{
print "End GMIoutl.Zip\n";
}
return $func_exit;
} #end of Zip sub
Am I even doing this right? Any suggestions?? Any help would be much appreciated!

New Topic/Question
Reply


MultiQuote





|