Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > detecting links

Reply
Thread Tools

detecting links

 
 
jsowers@csc.com
Guest
Posts: n/a
 
      07-03-2003
Is there any simple way to determine if a reference returned via readdir
is a soft- or hardlink rather than a directory or filename.
None of my perl books seem to show any way of telling.

Thanks
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      07-03-2003
>>>>> "j" == jsowers <> writes:

j> Thanks, but not quite the answer. readlink will return the name of
j> the directory/file which the link points to. I need something
j> equivalent to the '-d' to determine if an item is a directory.
j> Basically, I want to avoid following the link when walking a
j> directory tree.

perldoc -f -X

uri

--
Uri Guttman ------ -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      07-03-2003
<> wrote:

> Thanks, but not quite the answer.



Huh? It looks like the answer to me...


> readlink will return the name of the
> directory/file which
> the link points to.



Or undef if it is not a symbolic link.


> I need something equivalent to the '-d' to determine
> if an item is a directory.



That is not the same question, and you already know the answer
to that question.


> Basically, I want to avoid following the link when walking a directory
> tree.



Select those that are not symbolic and are directories (untested):

my @dirs_not_links = grep { !readlink() and -d } @directories;


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Steve Grazzini
Guest
Posts: n/a
 
      07-06-2003
Joe Smith <> wrote:
> In article <be1uub$9dj$>, <> wrote:
>> I need something equivalent to the '-d' to determine if an
>> item is a directory.

>
> Simply test for symlink _before_ testing for directoryness.
>
> if (-l $item) {
> (-d _) and print "Symlink to a directory\n";

^^^^
This will never be true.

> (-f _) and print "Symlink to a file\n";
> (-e _) or print "Broken symlink; target does not exist\n";

^^^^
And this will always be true.

You'll need to do a regular stat() inside the block -- otherwise
the special _ filehandle will refer to the results of the lstat()
and you know already that the *symlink* exists and is neither
file nor directory.

--
Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
URI.regexp buggy for detecting links? Stephan Meier Ruby 0 09-17-2009 08:06 PM
FF Crashes on Links within Links Puma Firefox 10 02-17-2009 07:12 PM
Make A Shorter Link - no new links accepted, old links still work. why? Computer Support 7 01-02-2007 09:45 PM
Site Links and Physical WAN Links =?Utf-8?B?RW5mb1BhdWw=?= MCSE 2 03-22-2005 09:23 AM
Exchange Links < Western Cartoon Cards > Exchange Links www.westerncartooncards.ca HTML 2 07-12-2004 07:59 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57