Reading Directories w/ Perl 
Author Message
 Reading Directories w/ Perl

[ posted and mailed ]

-> I'm stumped on this and I'm sure there is a very easy solution so hopefully
-> someone can help me out.  All I need to do is be able to look at a specific
-> directory with my script and get all of the filenames within that directory.
-> It doesn't even need to recursively go through the whole directory tree.
->
-> I just want to be able to feed it a directory name and get the names of the
-> files it contains...that's all.  Any help would be appreciated.  Thanks!!

perldoc -f opendir
perldoc -f readdir

HTH

Bob Trieger

" Cost a spammer some cash: Call 1-800-400-1972
  Ext: 1949 and let the jerk that answers know
  that his toll free number was sent as spam. "



Fri, 29 Dec 2000 03:00:00 GMT  
 Reading Directories w/ Perl

Quote:

>I'm stumped on this and I'm sure there is a very easy solution so hopefully
>someone can help me out.  All I need to do is be able to look at a specific
>directory with my script and get all of the filenames within that directory.
>It doesn't even need to recursively go through the whole directory tree.

>I just want to be able to feed it a directory name and get the names of the
>files it contains...that's all.  Any help would be appreciated.  Thanks!!

$ perldoc -f readdir
=item readdir DIRHANDLE

Returns the next directory entry for a directory opened by opendir().
If used in a list context, returns all the rest of the entries in the
directory.  If there are no more entries, returns an undefined value in
a scalar context or a null list in a list context.

If you're planning to filetest the return values out of a readdir(), you'd
better prepend the directory in question.  Otherwise, because we didn't
chdir() there, it would have been testing the wrong file.

    opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";

    closedir DIR;

--
Kelly William Hirano                        Stanford Athletics:




Fri, 29 Dec 2000 03:00:00 GMT  
 Reading Directories w/ Perl

Quote:
> I just want to be able to feed it a directory name and get the names of the
> files it contains...that's all.  Any help would be appreciated.  Thanks!!

> Marius

I think .. If all you want is the FILENAMES.. GLOB() is a simpler
function.


have the path attached)

--
Chuck Maier
CDM Consulting Services
http://www.cdmcon.com
(610) 943-2726



Sat, 30 Dec 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Reading Directories w/ Perl

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

3. CGI Module, Reading a Directory into an Array

4. Reading Directory Structure

5. Read UNC directory

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

7. read recursive directories

8. reading directories

9. looking for better way to read from directories

10. Read UNC directory

11. read directory question

12. problems with reading a file from a directory

 

 
Powered by phpBB® Forum Software