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

Where can I find the extention I'm looking for in a File::Find::? expression. I want to find a file name, so would it be File::Find::Basename or Name? On the other hand I think it is really cool that we can place pictures on our home nodes. However, I haven't figured how to do it yet. Can someone point me in the right direction. curtisb --- "Learning Perl one day @ a time!"
  • Comment on Question about File::Find and Home Node

Replies are listed 'Best First'.
(ar0n) Re: Question about File::Find and Home Node
by ar0n (Priest) on Nov 02, 2000 at 03:03 UTC
    From perldoc File::Find:
    The wanted() function does whatever verifications you want. $File::Find::dir contains the current directory name, and $_ the current filename within that directory. $File::Find::name contains "$File::Find::dir/$_".
    If you just want the filename, not the full path and filename, use $_.

    You have to be level 5 (monk) or higher to be able to put up a picture.

    [ar0n]

Re: Question about File::Find and Home Node
by moen (Hermit) on Nov 02, 2000 at 03:06 UTC
    You need to be at least monk to get the picture there legally :o)

    File::Find store the current filename in $_, so:
    #!/usr/bin/perl use File::Find; $path = '/home/perl'; find(sub{push(@files, $_) unless (-d $_)}, $path); print @files;
    and @files will hold the filenames.
Re: Question about File::Find and Home Node
by elwarren (Priest) on Nov 02, 2000 at 05:24 UTC
    This is the output from the find2perl script. It will search for files with that end with .bat and print out a list of filenames.

    The key to this code is the /^.*\.bat$/ which is basically looking for any string [ ^.* ] that matches .bat [ \.bat ] at the end of the line [ $ ] The backslash in front of the period tells perl to match a period instead of any single character.
    #!/usr/bin/perl require "find.pl"; # Traverse desired filesystems &find('.'); exit; sub wanted { /^.*\.bat$/ && print("$name\n"); }
Re: Question about File::Find and Home Node
by curtisb (Monk) on Nov 02, 2000 at 21:20 UTC
    Thanks, I think that I understand File::Find a little bit better now. curtisb