从OSX上的默认Perl,如何解压缩到文件夹? [英] From Default Perl on OSX, How To Unzip To Folder?

查看:101
本文介绍了从OSX上的默认Perl,如何解压缩到文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图避免包含其他库并将其简化在OSX上,使用自Snow Leopard以来OSX附带的默认Perl .我还试图避免炮轰Bash 以运行解压缩.我发现此示例几乎可以正常工作,但死于此行:

I'm trying to avoid having to include other libraries and keep this simple on OSX, using the default Perl that ships with OSX since Snow Leopard. I'm also trying to avoid shelling out to Bash to run the unzip. I found this example almost works, but dies on this line:

my $fh = IO::File->new($destfile, "w") or die "Couldn't write to $destfile: $!";

出现此错误:

无法写入/tmp/mytest/Install Norton Security.localized//:是test7.pl第42行的目录.

Couldn't write to /tmp/mytest/Install Norton Security.localized//: Is a directory at test7.pl line 42.

以前,我将文件夹"Install Norton Security.localized"压缩到mytest.zip并将其粘贴在/tmp中.然后,我创建了一个目录/tmp/mytest.然后,我使用

Previously, I zipped the folder "Install Norton Security.localized" to mytest.zip and stuck it in /tmp. I then created a directory /tmp/mytest. Then, I ran this script with

unzip("/tmp/mytest/mytest.zip","/tmp/mytest");

我还对该脚本进行了一次lint语法检查,结果一切正常-并没有像其他许多Perl zip库一样警告我缺少该库.

I also did a lint syntax check on the script and it came back okay -- didn't warn me about missing libraries like many other zip libraries for Perl.

您建议的解决方法是什么?

What do you suggest is the fix?

推荐答案

此例程在较旧的OSX上有效,并且不涉及太多代码行.它还处理子文件夹.

This routine works on older OSX and doesn't involve as many lines of code. It also handles subfolders.

#!/usr/bin/perl

use strict;
use warnings;

use Archive::Zip qw(:ERROR_CODES :CONSTANTS);

my $sSource = "/tmp/mytest.zip";
my $sDest = "/tmp/mytest";

x_unzip($sSource,$sDest);

sub x_unzip {
    my ($zip_file, $out_file, $filter) = @_;
    my $zip = Archive::Zip->new($zip_file);
    unless ($zip->extractTree($filter || '', $out_file) == AZ_OK) {
        warn "unzip not successful: $!\n";
    }
}

来源: https://gist.github.com/mshock/4156726

这篇关于从OSX上的默认Perl,如何解压缩到文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆