简体   繁体   中英

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. 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

    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.

It sounds like you already know how to call out to the system tar command so I'll leave it at that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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