Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Permission & size are not visible

by gaurav (Sexton)
on Jun 19, 2013 at 09:03 UTC ( [id://1039746]=note: print w/replies, xml ) Need Help??


in reply to Re: Permission & size are not visible
in thread Permission & size are not visible

Hi Corion,Sorry! but I haven't got this answer specially this line "you'd better prepend the directory in question". As its already visible in code :

 opendir DH,"/home/gaurav/Documents" or die "couldn't open the directory :$!";

that directory is there,if its make you annoy than sorry because m newbie

Replies are listed 'Best First'.
Re^3: Permission & size are not visible
by Corion (Patriarch) on Jun 19, 2013 at 09:05 UTC

    Just look at the code after the second paragraph of readdir, where the intended location of "prepend" is shown. The location is not in the readdir() call, but in the later usage, because readdir() only returns the bare name, not the full path to the directory entry.

    @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);

      Thanks a lot

Re^3: Permission & size are not visible
by smls (Friar) on Jun 19, 2013 at 09:39 UTC

    Either prepend the directory name when doing the file tests inside the loop:

    my $dir = "/home/gaurav/Documents"; opendir my $dh, $dir or die "Couldn't open $dir: $!"; while (readdir $dh) { next if $_ eq "." or $_ eq ".." ; print $_, " " x (30 - length($_)); my $file = "$dir/$_"; # ...do file tests against $file here }

    Or use chdir to change the working directory before entering the loop where you do the file tests:

    my $dir = "/home/gaurav/Documents"; opendir my $dh, $dir or die "Couldn't open $dir: $!"; chdir($dir); while (readdir $dh) { next if $_ eq "." or $_ eq ".." ; print $_, " " x (30 - length($_)); # ...do file tests against $_ here }
      Thanks @smls...Thanks a lote

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found