如何在 Perl 中压缩多个文件?
如何 tar 多个目录并附加具有某种模式(如“.txt”)的文件,并排除某些目录并将某些模式(如“.exe”)全部排除到单个 tar 文件中。要点是目录数量未知(动态),所以我猜我需要循环遍历?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用 Archive::Tar 并填充
@filelist 与 Class::Path (特别是
Class::Path: :Dir
的recurse
方法)I'd use Archive::Tar and populate
@filelist
with Class::Path (specificallyClass::Path::Dir
'srecurse
method)假设您已经使用 File::Find 找出了想要的文件,那么类似的操作
可能会起作用。但您可能会发现命令行太长。
在这种情况下,可以将文件列表写入文件并使用该选项
(请不要告诉我您不允许写入文件)
Assuming you have worked out what files you want using File::Find then something like
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
(and please don't tell me you are not allowed to write to files)
如果由于某种原因您不能或不允许安装基本系统之外的其他模块,您可以使用 File::Find 而不是 Class::Path。
听起来您已经知道如何调用系统 tar 命令,所以我就这样吧。
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.