Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: -s file test operator only works in same directory

by dbuckhal (Hermit)
on Dec 08, 2017 at 03:22 UTC ( #1205143=note: print w/replies, xml ) Need Help??


in reply to -s file test operator only works in same directory

One thing that has helped me in similar situations was to change into the directory containing the files of interest. For example, note the tiny changes to your code:

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: $!"; chdir $dir; # added chdir while(my $file = readdir DIR) { next unless -f $file; # simplified fil +e check next if($file =~ m/^\./); # removed quotes 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;

Hope it works out for you!

--Derrick

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1205143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2022-01-20 22:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?