【发布时间】:2019-11-16 23:45:01
【问题描述】:
基本问题。
我想使用 Perl 的 Archive::Tar 模块来备份东西。我想使用Archive::Tar 来备份文件和文件夹以及文件夹中的文件。使用我当前的代码,前两个有效,但第三个无效。
重现步骤:
- 创建示例目录。
- 在示例目录中,创建两个目录和一个 .txt 文件。
- 使用 vim,在 .txt 文件中写入任何内容。
- 在示例目录的其中一个目录中,重复步骤二和三。
- 在示例目录中,创建一个 perl 脚本。
- 将以下代码复制到脚本中。
- 运行脚本。在框中,键入 .txt 文件的名称和两个目录。
- 按下大压缩按钮。
- 在压缩目录中打开新的 .tbz 文件。
代码。
use strict; use warnings;
use Archive::Tar;
use Tk;
my $mw = MainWindow -> new;
$mw -> Label ( -text => "Please type the files you wish to backup, separated by spaces." ) -> pack;
my $inputEntry = $mw -> Entry ( -width => 30 );
$inputEntry -> pack;
$mw -> Button ( -text => "Compress!", -command => sub { compress() } ) -> pack;
MainLoop;
sub compress {
my $input = $inputEntry -> get;
my @input;
unless ( $input !~ m/ / ) {
@input = split ( m/ /, $input );
} else {
@input = ( $input );
}
Archive::Tar -> create_archive ( "TEST.tbz", COMPRESS_BZIP, @input )
}
【问题讨论】:
-
Iirc,您必须明确列出每个文件。仅传递一个目录不会自动递归地包含该目录中的所有内容。
-
啊。我想我明白了。