Quote:
quote:
well its not working because as soon as it checks for the files which are not accessible gives the
output "the directory does not exist" which is actually because of permission problem...
|
erm, just check if the file is readbable in the looop then:
Code:
my $path = "/path/to/dir"; # this is the dir you want to open
die ("$path: No permissions") unless (-r $path); # -r $path checks its readable, die if not
opendir(DIR, $path) || # try to open your directory
die "Cannot opendir $path: $!"; # if you can't print an error and die
for(sort readdir(DIR)) { # loop through the files in the dir, in sorted order
die ("$_: No permissions") unless (-r $_); # <---- Checks file is readable, dies if it isn't
print "$_\n"; # print their names
}
closedir(DIR); # close directory
Gives me:
Code:
charlie@charlie:~$ su
Password:
charlie:/home/charlie# touch aaa
charlie:/home/charlie# chmod 700 aaa
charlie:/home/charlie# exit
exit
charlie@charlie:~$ ./tmp.pl
.
..
.ICEauthority
.Trash
.Xauthority
Perspectives From The World Social Forum.doc
aaa: No permissions at ./tmp.pl line 9.
charlie@charlie:~$
Quote:
quote:
And my concern is regarding inside any home directory like /home/denzil/temp or
/home/jessica/tmp...
|
Not sure what you mean here
Quote:
quote:
Please tell me how to suppress the default error I mean to catch the
default error and put the condition for that
|
I think you're asking me to tell you how to check if a file is readable.
I don't know what a "default error" is. You can say
Code:
if (-r $file) { # if the file is readable
# do something
}
else { #otherwise
# do something else
}
hope that helps
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock:
http://charlieharvey.org.uk