How can I tar multiple files in Perl?

风流意气都作罢 提交于 2019-12-11 02:34:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!