问题
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?
回答1:
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)
回答2:
I'd use Archive::Tar and populate @filelist
with Class::Path (specifically Class::Path::Dir
's recurse
method)
回答3:
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.
来源:https://stackoverflow.com/questions/2545955/how-can-i-tar-multiple-files-in-perl