How can perl tell the difference. Or rather how can I test the
symlink to see if it points at a real openable directory.
Looking through the `stat' function, I'm not imagining a way to get at the
target of the symlink for a test.
Oops.. daydreaming and forgot lstat. But still for expressions where
stat is used like:
my @dir = grep { /^\w/ && -d "./$_" } readdir(DIR);
How would I check if the item passing the -d test is really a symlink.
Or maybe it would be better to find all the symlinks first and see if
they are directories.
The aim here is to establish if symlinks are pointing to directories
or if the directory is a normal directory.
Once that is established, then we want to test if there is an
`index.htm[l]' behind the directories.
So first establish if we are dealing with a real directory or symlink
Note:
(the first information is for admins use, Not for more coding in the
perl script so it can just be printed and forgotten. (admin trying
to setup a few directories that house symlinks to a host of other
things.)
The second part is for further coding, generate a formatted html page
with the index.html files setup as a list of hrefs.
(Not asking for help on that part (as yet anyway))
The -X operators follow the symlink.
if (-d $symlink && -r $symlink) {
print "$symlink points to a readable directory\n";
print "and you can chdir to it\n" if -x $symlink;
} else {
print "$symlink is not a directory or it is not readable\n";
}
Ok thanks... I'd already posted a followup on my own post before I saw
yours.. you've answered all I needed for now... thanks again.
> The -X operators follow the symlink.
Where is there a list of the -X operators
perldoc perlop doesn't mention it. Or at least
/\-X in that page doesn't find anything.
> if (-d $symlink && -r $symlink) {
> print "$symlink points to a readable directory\n";
> print "and you can chdir to it\n" if -x $symlink;
> } else {
> print "$symlink is not a directory or it is not readable\n";
> }
So first how can I tell they are symlinks or not.
This doesn't do it after pullin all dir in to @dir
for(@dir){
if(lstat $_){ print "$_ is symlink\n";
}
}
It prints both symlinks and real directories.
The -l test will tell you if a file is a symlink and readlink() will
read the contents of that symlink.
if ( -l $file && -d readlink $file ) {
print "$file is a symlink that points to a directory\n";
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
They are listed in perlfunc.
perldoc -f -X
from perldoc perlfunc
-l File is a symbolic link.
> The -l test will tell you if a file is a symlink and readlink() will
> read the contents of that symlink.
>
> if ( -l $file && -d readlink $file ) {
> print "$file is a symlink that points to a directory\n";
> }
Ahh nice... thanks