For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > July 2004 > How to find directories









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 How to find directories
Bern

2004-07-23, 3:56 pm

A newbie question:

I need to find all the subdirectories in a directory. I know how to
get the content of the directory but I don't know how I can identify
directories and for that matter any other kind of files under the same
directory.

I can I do that?

Thanks
Bern
Paul Lalli

2004-07-23, 3:56 pm

On Fri, 23 Jul 2004, Bern wrote:

> A newbie question:
>
> I need to find all the subdirectories in a directory. I know how to
> get the content of the directory but I don't know how I can identify
> directories and for that matter any other kind of files under the same
> directory.
>
> I can I do that?


To just determine whether a given directory entry is a file, directory,
link, etc, lookup:
perldoc -f -x

To recursively search directories, lookup:
perldoc File::Find

You'll want to use both of those to carry out your goal. Once you've read
them, if you have questions, let us know. Then make an attempt, and if it
doesn't work right, feel free to ask for help.

Paul Lalli
Jürgen Exner

2004-07-23, 8:56 pm

Bern wrote:
> I need to find all the subdirectories in a directory. I know how to
> get the content of the directory but I don't know how I can identify
> directories


perldoc -f -d

jue


Mladen Gogala

2004-07-24, 3:56 am

On Fri, 23 Jul 2004 10:16:15 -0700, Bern wrote:

> A newbie question:
>
> I need to find all the subdirectories in a directory. I know how to
> get the content of the directory but I don't know how I can identify
> directories and for that matter any other kind of files under the same
> directory.
>
> I can I do that?


You use a trick:

find2perl $HOME -type d -print

That will produce the subroutine that you can use.


--
A city is a large community where people are lonesome together.

Sponsored Links







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

Copyright 2008 codecomments.com