Reading directories 
Author Message
 Reading directories

Hello.
     I have been programming in PERL for about 2 months now and am running
into a problem.  I am reading a directory and trying to eliminate any
directories when I read it so only files appear in the array.  I am using the
example in the camel book to eliminal the . and .. but cannot eliminate any
directoried.  Is a directory a symbolic link?  I am running under a UNIX
system.  If you can help me I would appreciate it greatly.  Thank you in
advanced for your help.

                        HAROLD



Mon, 28 Sep 1998 03:00:00 GMT  
 Reading directories

Quote:

> Hello.
>      I have been programming in PERL for about 2 months now and am running
> into a problem.  I am reading a directory and trying to eliminate any
> directories when I read it so only files appear in the array.  I am using the
> example in the camel book to eliminal the . and .. but cannot eliminate any
> directoried.  Is a directory a symbolic link?  I am running under a UNIX
> system.  If you can help me I would appreciate it greatly.  Thank you in
> advanced for your help.

Try something like the following:


closedir(MYDIR);

# At this point you have a list of all the thiings in the current
directory,
# files and subdirectories included.  now you just need to get rid of
the
# directories


the

of
# the current directory.

Look in the Camel for file test operators.

cheers,

-Scott
--

Systems Programmer  Fax: 512-994-2715  URL:
http://www.cbi.tamucc.edu/~duff/
Conrad Blucher Institute for Surveying and Science
6300 Ocean Drive, Corpus Christi  TX 78412-5503



Mon, 28 Sep 1998 03:00:00 GMT  
 Reading directories

Quote:
> I am reading a directory and trying to eliminate any directories
> when I read it so only files appear in the array.

You need to use the -f operator to test for plain files. The usual error
is forgetting that readdir only returns filename, and that unless you're
reading the current directory, you need to prepend the pathname of the
directory before a file test operator will work. If you're doing
something like this:

$dirname = "/some/directory/name";



filenames, not the fully qualified names that will let the system find
the files you're talking about. You need something more like:

$dirname = "/some/directory/name";

closedir( DIR);

{

Quote:
}

or, more usefully for some purposes:


{
        if (-f ( $pathname = "$dirname/$e"))
        {

        }

Quote:
}

which will collect the full pathnames of the regular files in the
directory. You also need to test for errors!

Quote:
> Is a directory a symbolic link?

No, it isn't.


#!perl: ftp .../CPAN/ports/msdos/tips-tricks/hbp_30.zip



Tue, 29 Sep 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Reading directories, entering directories, chaning file permissions...

2. Reading Directory Structure

3. help selecting and displaying specific files after reading directory:

4. reading directories

5. read directory question

6. Read Directory

7. Reading Directory

8. Reading Directories w/ Perl

9. Help reading directories and displaying contents

10. Read directory and not files

11. Reading Directories w/ Perl

12. Reading Directories

 

 
Powered by phpBB® Forum Software