1

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!

gregnnylf94
  • 370
  • 3
  • 16
  • Okay I would also like to add, I have now tried writing the commands to a batch file to execute, with no luck... same thing. – gregnnylf94 Jun 21 '17 at 13:08

2 Answers2

0

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.

  • Just to clarify, it's not the extraction of the PDFs, it's either extraction. If you run the XMLs first XMLs get extracted and not the PDFs and vice versa. (Because the 7zip has been processed already...) – gregnnylf94 Jun 21 '17 at 12:26
  • This is the only error I have to go off of.... `No files to process Files: 0 Size: 0 Compressed: 3114222` – gregnnylf94 Jun 21 '17 at 13:00
  • I feel the 7z process is not returning back to perl code which may be making it hung. if possible you can attach a sample 7z file, I can run the code across & check it. –  Jun 22 '17 at 10:28
  • I really appreciate it, but I solved it. It was actually working perfectly, the XMLs weren't in the correct directory. I should have checked that first -_-. – gregnnylf94 Jun 22 '17 at 12:14
0

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.

gregnnylf94
  • 370
  • 3
  • 16