ds can now handle relative and absolute paths
This commit is contained in:
parent
88b388993d
commit
c90378dce3
@ -24,18 +24,39 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use File::Find;
|
||||
use Cwd;
|
||||
use Getopt::Long;
|
||||
|
||||
if (@ARGV == 0) {
|
||||
my $help;
|
||||
my $verbose;
|
||||
|
||||
my $usage = "Usage: $0 <directory_path>\n";
|
||||
|
||||
GetOptions(
|
||||
'help|h' => \$help,
|
||||
'verbose|v' => \$verbose,
|
||||
) or die $usage;
|
||||
|
||||
if ($help) {
|
||||
print <<EOF;
|
||||
\nUsage: $0 <directory_path>
|
||||
|
||||
\n$usage
|
||||
Calculate the size of a directory and its contents.\n
|
||||
|
||||
Options:
|
||||
-h, --help Show this help message and exit
|
||||
-v, --verbose List all files and folders encountered
|
||||
EOF
|
||||
exit;
|
||||
}
|
||||
|
||||
if (@ARGV != 1) {
|
||||
die $usage;
|
||||
}
|
||||
|
||||
my $dir_path = $ARGV[0];
|
||||
|
||||
$dir_path = Cwd::abs_path($dir_path);
|
||||
|
||||
unless (-d $dir_path) {
|
||||
die "$dir_path is not a directory\n"
|
||||
}
|
||||
@ -53,6 +74,15 @@ sub calculate_size {
|
||||
|
||||
if (-f $file) {
|
||||
$total_size += -s $file;
|
||||
if ($verbose) {
|
||||
print "File: $file\n"
|
||||
}
|
||||
}
|
||||
|
||||
if (-d $file) {
|
||||
if ($verbose) {
|
||||
print "Directory: $file\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user