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

To return the location and name of the file. Im trying to figure out a way to get the file name and also the location of the file. What I currently have gives me list of dirs but I dont thin the file is located in that directory. Any help would be appreciated. Thanks Fue
use File::Find; #Opens file to write to die("Cannot open Log file to read from.") unless(open(FILE, ">/cdw/home_dir/s006258/list.txt")); find (\&change_sas,"/cdw/home_dir"); sub change_sas { my $filename=$_; if (-d $filename) { print FILE "In DIR $filename\n"; } if (-f $filename && $filename=~/sam_norep/) { print FILE "Found $filename\n"; } } close(FILE);

Replies are listed 'Best First'.
Re: Using File:Find
by GrandFather (Saint) on Nov 28, 2005 at 22:38 UTC

    From the File::Find documantation:

    $File::Find::dir is the current directory name,
    $_ is the current filename within that directory
    $File::Find::name is the complete pathname to the file.

    DWIM is Perl's answer to Gödel
      Thanks, I didnt know thats what documentation meant... Thanks again...
Re: Using File:Find
by ambrus (Abbot) on Nov 28, 2005 at 22:39 UTC

    From the docs of File::Find:

    The wanted function takes no arguments but rather does its work through a collection of variables.

    $File::Find::dir is the current directory name,
    $_ is the current filename within that directory
    $File::Find::name is the complete pathname to the file.

Re: Using File:Find
by marto (Cardinal) on Nov 28, 2005 at 22:42 UTC
    Hi Fuism,

    A quick example program that takes the path as an argument such as perl scriptname.pl c:\windows
    #!/usr/bin/perl use strict; use warnings; use File::Find; my $TargetPath = $ARGV[0]; find (\&ProcessTree,$TargetPath); sub ProcessTree { print "Directory: $File::Find::name\n" if -d; print "File: $File::Find::name\n" unless -d; }
    Hope this helps.

    Martin