Determine the contents of a directory tree? : File « File « Perl






Determine the contents of a directory tree?

    

#find function side effect variables
#VARIABLE NAME    CONTENTS
#$dir             The current directory name
#$_               The current file name within that directory

    #!/usr/local/bin/perl -w

    use Getopt::Long;
    use File::Find;

    my $ret = GetOptions ("d|directory:s");
    my $directory = $opt_d || die "Usage: $0 -d directory\n";

    sub wanted
    {
       print "Dir =<$dir>\n";
       print "Name=<$name>\n";
       print "File=<$_>\n";
    }

    find(\&wanted, $directory);

   
    
    
    
  








Related examples in the same category

1.Copy files
2.Copying a file using the File::Copy
3.Create a directory tree
4.File finder and callback
5.File size with FIELDS
6.Find file
7.Find out if there's a copy of the dir program on this computer
8.File find closure
9.Using a Callback
10.Extracting file names from paths
11.$File::Find::prune = 1 if /dir1/;