我感兴趣的是使用File::Find
或IO::Compress::Gzip
(或类似模块)的功能来递归压缩文件。但是,我不清楚perldoc和其他研究如何仅在文件大于给定大小时指定压缩。另外,如果我已经确定了目录的总大小(当然是递归地),有什么方法可以跟踪进度吗?
这是我到目前为止所做的:
use warnings;
use strict;
use File::Find;
sub totatlDirSize($) {
# Set the lexical variable for the passed directory.
my $directory = shift;
# Initialization of variables.
my $total_size = 0;
# Recurse into subdirectories to determine total directory size.
find(sub { $total_size += -s if -f $_ }, "$directory");
# Return the total_directory size to the calling function.
return $total_size;
}
# This is where I would like to add in recursive compression...
# Some pseudo-code might be:
# foreach ( file larger than $given_size ) {
# gzip $file
# print $progress_indicator --> i.e., percentage of total, progress bar, etc.
# }
# Have progress indicator show completion.
这是可能的吗?或者,我是在做梦还是完全错过了什么?
我希望用户能够传入一个目录,这需要递归操作。我是否必须使用该目录中的文件枚举数组?怎么做的?
编辑:更新以提高可读性。