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?
I'd use Archive::Tar and populate @filelist
with Class::Path (specifically Class::Path::Dir
's recurse
method)
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.
精彩评论