2017-06-20 35 views
1

好吧我處於完全損失狀態。7Zip從2個不同的子文件夾中執行2次提取(僅限首次執行)

我想從7zip文件中提取所有的XML和PDF。 該文件內有更多的東西,所以我只想從PDF文件夾和XML文件夾中提取。留下文件結構,而不是在任何其他文件夾中搜索。

我正在使用7Zip命令行來執行此操作。

我有兩個子例程,我執行它們幾乎是相同的。

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; 
} 

,我使用它是這樣的...

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); 
    } 

當執行的PDF文件中提取得到,但不是個XML。 我收到一個錯誤,沒有要處理的文件。

我覺得7zip掛在上次調用的文件上。有沒有辦法關閉它或釋放文件?

任何幫助表示讚賞,浪費很多時間在這。

謝謝!

+0

好吧我還想補充一點,我現在已經嘗試將命令寫入批處理文件來執行,沒有運氣......一樣的事情。 – gregnnylf94

回答

0

用戶錯誤...正常工作。 我有一個條件:

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; 
    } 

和我解壓第一個文件,該XML是不是在正確的道路......有人沒有按照模式。非常尷尬的謝謝你的迴應。

0

檢查退出狀態$?,如果您覺得它掛起。 你也可以先嚐試提取xml然後pdfs來真正確定,如果提取pdfs命令正在發佈。

共享控制檯輸出,它可以顯示更多的細節。

+0

我會回來的錯誤的詳細信息。 – gregnnylf94

+0

只是爲了澄清,這不是提取PDF文件,而是提取。如果您首先運行XML,則XML將被提取,而不是PDF,反之亦然。 (因爲7zip的已處理已經...) – gregnnylf94

+0

這是我必須去掉.... '沒有要處理的文件 文件的唯一錯誤:0 大小:0 壓縮:3114222' – gregnnylf94