Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Before a processing, I need to verify the output directory doesn't contain old results. How can I determine if a type of file (i.e. *.fa or *.log) exists in a directory?
  • Comment on How to verify a type of file exists in a directory?

Replies are listed 'Best First'.
Re: How to verify a type of file exists in a directory?
by davidrw (Prior) on Aug 26, 2005 at 17:33 UTC
    perldoc -f glob (or opendir/readdir) and perldoc -f -X should get you to a good start. I'm sure solutions could be constructed with File::Find (or File::Find::Rule) as well.
Re: How to verify a type of file exists in a directory?
by brian_d_foy (Abbot) on Aug 26, 2005 at 20:45 UTC

    If you are dealing with one directory and not descending into subdirectories, you can use a glob. If you get files back from the glob, then you know they exist.

    my @files = glob( "*.fa *.log" );

    Note: In this example the current directory has to be the output directory, but you could also use paths in the glob.

    --
    brian d foy <brian@stonehenge.com>
    Subscribe to The Perl Review