Hello,
I have made a perl script which takes the files from a directory listed on the command line and places them into an array of hashes with key/value pairs path:full path to file, size:size of file in bytes, and id:sha256sum of file.
It works fine when I use its own directory, but it returns "undef" on the id value when used in other directories, and the $! error is "no such directory or file found", which I find quite odd considering that it lists the filenames sha256sums just fine.
use strict;
use warnings;
use Data::Dumper qw(Dumper);
use File::Spec;
use Digest::SHA qw(sha256_hex);
print join("\n", @ARGV),"\n\n";
#print Dumper \@ARGV;
my $dir = $ARGV[0];
my $url = $ARGV[1];
my @array;
opendir DIR, $dir or die "cannot open dir $dir: $!";
while(my $file = readdir DIR) {
next unless(-f "${\File::Spec->catfile($dir, $file)}");
next if("$file" =~ m/^\./);
print "${\File::Spec->rel2abs($file)}\n";
my %hash = (
path => File::Spec->rel2abs($file),
size => -s $file,
id => sha256_hex($file),
);
push(@array, \%hash);
}
closedir DIR;
print Dumper sort \@array;