[EMAIL PROTECTED] wrote:
"Chas. Owens" <[EMAIL PROTECTED]> writes:
On 1/10/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
I'm working on a little script that will generate an html page from a
directory full of symlinks to target directories. However in some
cases there may be symlinks that point to regular files.
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.
snip
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 -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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/