简体   繁体   English

如何在Perl中tar多个文件?

[英]How can I tar multiple files in Perl?

How can I tar multiple directories and also append files with some pattern like '.txt' and exclude some directories and exclude some patterns like '.exe' all into a single tar file. 我如何tar多个目录,并附加一些模式,如'.txt',并排除一些目录,并将一些模式,如'.exe'全部排除在一个tar文件中。 The main point is the number of directories are unknown(dynamic), so I need to loop through I guess? 主要的一点是目录的数量是未知的(动态的),所以我需要循环通过我猜?

我使用Archive :: Tar并使用Class :: Path填充@filelist (特别是Class::Path::Dirrecurse方法)

Assuming you have worked out what files you want using File::Find then something like 假设你已经使用File :: Find找出了你想要的文件

    my @dir = qw/a b/ ;
    system "tar -cvf mytar @dir" ;

might work. 可能有用。 But you might find that the command line is too long. 但是您可能会发现命令行太长。

In which case maybe write the list of files to a file and use the option 在这种情况下,可以将文件列表写入文件并使用该选项

   --files-from=NAME

(and please don't tell me you are not allowed to write to files) (请不要告诉我你不能写文件)

If for some reason you cannot, or are not permitted to, install additional modules beyond the base system you could use File::Find instead of Class::Path. 如果由于某种原因您不能或不允许在基本系统之外安装其他模块,则可以使用File :: Find而不是Class :: Path。

It sounds like you already know how to call out to the system tar command so I'll leave it at that. 听起来你已经知道如何调用系统tar命令,所以我会留下它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM