7Zip execute 2 extractions from 2 different subfolders (only first executes)

166 Views Asked by At

Okay I'm at a total loss.

I am trying to extract all the XMLs and PDFs from a 7zip file. There is more stuff inside said file, so I just want to extract from the PDF folder and the XML folder. Leaving the file structure behind and not searching in any other folders.

I am using the 7Zip command line to do this.

I have two sub routines that I execute which are almost identical.

sub Extract_pdfs_from_this
{
  my ($file, $destination) = @_;

  my $sevenzip_executable = '\\\\server\7-Zip\7z.exe';
  my $extract_pdfs = "$sevenzip_executable e -y  -o$destination $file output\\JETPDF\\DISB\\*.pdf ";

  print STDOUT "\n\nExtracting PDFs From $file \n>>$extract_pdfs \n";
  eval{system($extract_pdfs)};
  print STDOUT "Finished Extracting PDFs \n";

  return;
}

..

sub Extract_xmls_from_this
{
  my ($file, $destination) = @_;

  my $sevenzip_executable = '\\\\server\7-Zip\7z.exe';
  my $extract_xmls = "$sevenzip_executable e -y  -o$destination $file staging\\DISB\\OnBase\\*.xml ";

  print STDOUT "\n\nExtracting XMLs From $file \n>>$extract_xmls \n";
  eval{system($extract_xmls)};
  print STDOUT "Finished Extracting XMLs \n";

  return;
}

and I use it like so...

    my $in_extraction_directory = dirname(__FILE__);
    my $input_subdirectory = "$directory\\$subdirectory";
    my @in_seven_zip_files = Get_all_sevenzips_in($input_subdirectory);

    foreach my $sevenzip_file (@in_seven_zip_files)
    {
          $sevenzip_file = "$input_subdirectory\\$sevenzip_file";
      Extract_pdfs_from_this($sevenzip_file, $in_extraction_directory);
      Extract_xmls_from_this($sevenzip_file, $in_extraction_directory);
    }

When executed the PDFs get extracted but not the XMLs. I get an error, there are no files to process.

I feel like 7zip is hung up on the file from the previous call. Is there a way to close it or release the file?

Any help appreciated, much time wasted on this.

Thanks!

2

There are 2 best solutions below

0
gregnnylf94 On BEST ANSWER

User error... Works just how it should. I had a condition:

unless ($number_of_pdfs == $number_of_xmls)
    {
      print STDOUT "The number of PDFs and XMLs did not match!\n\n";
      print STDOUT "PDFs: $number_of_pdfs \nXMLs: $number_of_xmls\nFile: $sevenzip_file \nExtraction Directory: $output_directory\n\n";

      die;
    }

and in the first file I was extracting, the XML was not in the correct path... Someone didn't follow pattern. Very embarrassing thanks for the response.

4
AudioBubble On

Check exit status $?, if you feel it's hung. Also you can try first extracting xmls then pdfs to really make sure, if extracting pdfs command is making issue.

share console output, Which can show much details.