Question:
how do you unzip a .7z file using perl script?
2013-01-28 06:11:23 UTC
Say i have a .7z file in c:\Folder1 and i want to unzip it to c:\Folder2 with the same name as the .7z file. how do i do it?
Five answers:
Vin
2013-01-30 22:41:29 UTC
i am assuming you want to do this on your own PC. else don't use this code unless you are sure you know what you're doing. using the shell in for example a server environment can be dangerous. One sure don't want to use any user inputs with something like this.



With that said.



Download 7za.exe command line 7zip utility on this page: http://www.7-zip.org/download.html it is labeled "32-bit 7-Zip Command Line Version". Extract 7za.exe into some folder. I put things like that into a directory named C:\Program_Dropins



Below is something i slung together. In the past I have had to deal with archive files before. I think the code and comments pretty much speak for themselves. It should work if you have spaces in paths but normally I try to avoid spaces in windows scripts if i can.



Read the help file that comes with 7za.exe for plenty of options. If you are really new to 7zip command line I found this good page http://www.dotnetperls.com/7-zip-examples



Good luck!





#!/usr/bin/perl -w



use strict;



my %configs = (

'7zexe' => "C:\\Program_Dropins\\7zip\\7za.exe",

'dir1' => "C:\\Folder1",

'dir2' => "C:\\Folder2"

);



my $zip_file = '7zip.7z';



# note the -o must touch the output dir. its a 7zip thing not perl

# -y assumes yes to all promps



my $output = `\"$configs{'7zexe'}\" -y e \"$configs{'dir1'}\\$zip_file\" -o\"$configs{'dir2'}\"`;



if ($output =~ /Everything is Ok/g){

print "Worked\n";

}

else{

print "Sorry\n";

}



sleep 5;
moni
2016-11-12 09:05:22 UTC
Unzip 7z File
difelice
2016-08-10 11:56:31 UTC
There is no easy solution for this. First: directory c:abcd need to be shared. Second: This SMB share must be set up in the Linux /mnt listing before Perl is invoked. Third: For the 2d purpose - Perl is the worst choice for this. That's finished with the aid of 2 lines in the event you use bash script: smbmount //WindowsPcName/abcd /mnt -o username=consumer,password=pass,uid=500,gid=... Cp /mnt/xyz.Log /var/decide/abc/xyz.Log With Perl, that you could"T mount windows/Samba share. The best you are able to do is to invoke these 2 traces with the Perl function "procedure" and break out the detailed symbols where/if wanted.
2014-07-21 22:27:56 UTC
You can get Winrar for free from this link http://j.mp/1p3Pl0C

The best program you can use to decompress all the different kind of files is Winrar.

I hope it helps
TheMadProfessor
2013-01-28 06:40:46 UTC
You would have to invoke 7-Zip with the proper parameters. I don't have the documentation for it handy, so you'd have to open the app and read the help file for instructions how to run in batch mode.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...