For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2008 > need to find all the directories which have soft links in it









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author need to find all the directories which have soft links in it
Nag

2008-03-26, 7:11 pm

Hi all,

I have a parent directory which contains nearly 10 soft-links to other
directories, the linked directory may also contain soft-links to other
directories.it goes on like that till the directory doesn't contain any
soft-links. How can I get the list of all these directories ? Thanks in
advance

--
Thanks
Nagesh

Chas. Owens

2008-03-26, 7:11 pm

On Wed, Mar 26, 2008 at 10:33 AM, nag <nagesh.rvce@gmail.com> wrote:
> Hi all,
>
> I have a parent directory which contains nearly 10 soft-links to other
> directories, the linked directory may also contain soft-links to other
> directories.it goes on like that till the directory doesn't contain any
> soft-links. How can I get the list of all these directories ? Thanks in
> advance

snip

Use File::Find* and the -l operator**.

* http://perldoc.perl.org/File/Find.html
** http://perldoc.perl.org/perlfunc.html#-X


--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
Sandy

2008-03-26, 7:11 pm

On 26 =CD=C1=D2, 07:33, nagesh.r...@gmail.com (Nag) wrote:
>
> I have a parent directory which contains nearly 10 soft-links to other
> directories, the linked directory may also contain soft-links to other
> directories.it goes on like that till the directory doesn't contain any
> soft-links. How can I get the list of all these directories ? Thanks in
> advance


You can do opendir(), readdir() in the loop and test every entry with
'-l' operator: if (-l $entry) {...}.
perldoc -f -l
Then you can recursively go through all detected linked dirs (test if
they are dirs with '-d' operator). You may want to include a loop
detection logic, so you don't cycle forever if there is a loop

Do you necessarily need it in Perl? Consider calling 'find' if you are
on Unix. 'man find' for options

/sandy
http://myperlquiz.com/

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com