#!perl -w
###########################################################################
# Copyright (c) 1991-2002 Rational Software Corporation. All rights
# reserved.
# 
# Rational, the Rational logo, ObjecTime (and logo) are registered
# trademarks of Rational Software Corporation.
#
#    This script is provided in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Author: Simon Washbrook
#
###########################################################################
die "The first parameter must a directory\nUsage:\n\tperl FindFiles.pl <root directory for search>\n" unless (-d $ARGV[0]);

# Recursive search function that prints out the names of all the files found
sub PrintDirectoryFiles
  {
    my $Path = shift;
    # Parameter must be a directory ...
    return if (! -d $Path);
    # ... which can be read
    return if (! opendir (DIR, $Path));
    # Read the contents of the directory
    my @DirContents = readdir(DIR);
    closedir(DIR);

    my($File);
    foreach $File (@DirContents) {
      # Ignore the . and .. directories to avoid looping for ever
      next if (($File eq  ".") || ($File eq  ".."));
      # Print to standard out if it is a file
      print $Path . "/" . $File,"\n" if (-f $Path . "/" . $File);
      # Recurse into it if it is a directory
      PrintDirectoryFiles($Path . "/" . $File) if (-d $Path . "/" . $File);
    }
  }

# Recurse all directories printing files
PrintDirectoryFiles ($ARGV[0]);
