【发布时间】:2020-05-30 03:36:37
【问题描述】:
我正在使用Archive::Tar 模块对目录内容进行去皮。
我的脚本如下:
#!/usr/bin/perl -w
use strict;
use warnings;
use Archive::Tar;
use File::Find;
use Data::Dumper;
my $home_dir = "C:/Users/Documents/Vinod/Perl_Scripts/test/";
my $src_location = $home_dir."LOG_DIR";
my $dst_location = $home_dir."file.tar.gz";
my @inventory = ();
find (sub { push @inventory, $File::Find::name }, $src_location);
print "Files:".Dumper(\@inventory);
my $tar = Archive::Tar->new();
$tar->add_files( @inventory );
$tar->write( $dst_location , 9 );
脚本能够在位置C:/Users/Documents/Vinod/Perl_Scripts/test/ 中创建file.tar.gz 文件。
但是当我手动提取file.tar.gz 时,它会再次递归地创建一个完整的路径。所以LOG_DIR的内容将在C:/Users/Documents/Vinod/Perl_Scripts/test/file.tar/file/Users/Documents/Vinod/Perl_Scripts/test/LOG_DIR/位置可见
如何在提取时将C:/Users/Documents/Vinod/Perl_Scripts/test/LOG_DIR/ 中的内容放在C:/Users/Documents/Vinod/Perl_Scripts/test/file.tar/file/ 中。
【问题讨论】:
标签: perl