detecting links

Discussion in 'Perl Misc' started by jsowers@csc.com, Jul 3, 2003.

  1. Guest

    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
     
    , Jul 3, 2003
    #1
    1. Advertising

  2. Uri Guttman Guest

    >>>>> "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
     
    Uri Guttman, Jul 3, 2003
    #2
    1. Advertising

  3. <> 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
     
    Tad McClellan, Jul 3, 2003
    #3
  4. 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
     
    Steve Grazzini, Jul 6, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Reinemann

    Detecting of 'U' in a std_logic_vector

    Thomas Reinemann, Oct 28, 2004, in forum: VHDL
    Replies:
    4
    Views:
    675
    Allan Herriman
    Nov 3, 2004
  2. Praveen
    Replies:
    2
    Views:
    932
    Bert Cuzeau
    Apr 12, 2005
  3. www.westerncartooncards.ca

    Exchange Links < Western Cartoon Cards > Exchange Links

    www.westerncartooncards.ca, Jul 12, 2004, in forum: HTML
    Replies:
    2
    Views:
    1,289
    Toby Inkster
    Jul 12, 2004
  4. Stephan Meier

    URI.regexp buggy for detecting links?

    Stephan Meier, Sep 17, 2009, in forum: Ruby
    Replies:
    0
    Views:
    136
    Stephan Meier
    Sep 17, 2009
  5. Garrett Smith
    Replies:
    14
    Views:
    340
    David Mark
    May 26, 2009
Loading...

Share This Page