Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

File path added to file name variable

by deshdaaz (Novice)
on May 07, 2013 at 23:43 UTC ( #1032543=perlquestion: print w/ replies, xml ) Need Help??
deshdaaz has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Below is the code.

my @files = File::Find::Rule->name(qr/UFLEX.*stdf$/) ->file() ->in(cwd()); foreach my $file (@files) { print "$file\n";

The output is :

 /datalogs/TD+/prod/temp/UFLEX13_UD16B208.1apr25_03_45.stdf

I was expecting just the actual file name to be assigned to $file. Why is the path concatenated to my variable? If I use the "dot" to specify current working directory instead of cwd() it works well but then it's searching all the hidden dirs as well when the script is run through cron. My goal is to avoid running hidden . directories. Thanks for reading and helping. Deshdaaz.

Comment on File path added to file name variable
Select or Download Code
Re: File path added to file name variable
by toolic (Chancellor) on May 07, 2013 at 23:58 UTC
    To get just UFLEX13_UD16B208.1apr25_03_45.stdf, you can use File::Basename in your foreach loop:
    foreach my $file (@files) { print basename($file), "\n"; }

    I can't find any mention of basename in File::Find::Rule.

Re: File path added to file name variable
by deshdaaz (Novice) on May 08, 2013 at 00:07 UTC
    Never mind. Maxdepth does the trick.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1032543]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2014-10-25 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (141 votes), past polls