-5

perl.enter コードで zip ファイルを作成する必要があります。たとえば、既存のファイル名は 2.csv です。スクリプトで 2.zip にする必要があります。試してみました

my $file = 'dispatch_report_seg_flo.csv' ;
# Retrieve the namme of the file to archive.
print("Name the file to archive: ");

# Confirm the file exists, if not exit the program.
(-e $file) or die("Cannot find file `$file_nm`.\n");

# Zip the file.
print("Trying file name '$file.zip'");
system("zip 'dispatch.zip' '$file'");
my $file1 = 'dispatch.zip';
4

3 に答える 3

6

ファイル名に一重引用符が含まれていない限り、それは機能するはずです。より良い方法が 2 つあります。

  1. system($EXECUTABLE, @ARGS)、不必要にシェルを生成しません。

    system("zip", "dispatch.zip", $file);
    
  2. system($SHELL_COMMAND)これには、シェル コマンドの作成が必要です。

    # A poor substitute for String::ShellQuote's shell_quote
    sub shell_quote {
        my @s = @_;
        for (@s) { s/'/'\\''/g; $_ = "'$_'"; }
        return join(' ', @s);
    }
    
    system(shell_quote("zip", "dispatch.zip", $file));
    

    明らかに、最初の解決策の方が優れていますが、何らかのシェル リダイレクトを行いたい場合は、この解決策を使用することをお勧めします。

    system(shell_quote("zip", "dispatch.zip", $file) . ' >/dev/null');
    
于 2013-04-01T09:10:31.537 に答える
1

このリンクはあなたを助けるかもしれません... perlモジュールを使用してファイルを圧縮したい場合は、perlでtar.bz2ファイルを作成して読み取ります

use IO::Compress::Zip qw(:all);

  zip [ glob("*.xls") ] => "test_zip.zip"
    or die "some problem: $ZipError" ;

必要に応じてこれらの行を使用スクリプトに追加します

于 2013-04-01T09:08:49.987 に答える
-1

' 文字を削除します。

system("zip dispatch.zip $file");
于 2013-04-01T07:52:52.613 に答える