Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Beginners guide to File::Find

by tos (Deacon)
on May 25, 2003 at 19:28 UTC ( #260720=note: print w/ replies, xml ) Need Help??


in reply to Beginners guide to File::Find

Hi,

File::Find wasn't my friend in the past. Therefore i appreciate your interesting article. A few times i looked for possibility to work with File::Find as can be done with gnu-find regarding the maxdepth-feature.

The no_chdir-parameter seemed to me as a possible beginning for this.

But when i tested the concerning code-snipped in your article i couldn't recognize any difference between false or true no_chdir

# cat pf1 #! /usr/local/bin/perl use warnings; use strict; use File::Find; my $dir = shift @ARGV; find({wanted => sub {print $File::Find::name,"\n" if -d}, no_chdir => 0}, "$dir"); print "\n"; find({wanted => sub {print $File::Find::name,"\n" if -d}, no_chdir => 1}, "$dir");
given directory da
# find da da da/s1 da/s1/f1 da/s1/f2 da/s2 da/s2/sx da/s2/sx/sa da/s2/sx/f4 da/s2/sx/f5 da/s2/sy da/s2/f3 da/s3 da/s3/sz da/s3/sz/f7 da/s3/sz/f8 da/s3/f6 da/s4
pf1' output
# ./pf1 ./da ./da ./da/s4 ./da/s3 ./da/s3/sz ./da/s2 ./da/s2/sy ./da/s2/sx ./da/s2/sx/sa ./da/s1 ./da ./da/s4 ./da/s3 ./da/s3/sz ./da/s2 ./da/s2/sy ./da/s2/sx ./da/s2/sx/sa ./da/s1
What's the problem ?

greetings, tos


Comment on Re: Beginners guide to File::Find
Select or Download Code
Re: Re: Beginners guide to File::Find
by Limbic~Region (Chancellor) on May 25, 2003 at 23:32 UTC
    tos,
    As far as I can tell - there is no problem. I just spent about 20 minutes looking at the find2perl code as well as looking at the docs on File::Find. It doesn't appear that there is support for the gnu find's maxdepth option.

    But don't get mad, get even by checking out File::Find::Rule which does have a maxdepth option and is argued by some to be easier to use than File::Find.

    Cheers - L~R

Re: Re: Beginners guide to File::Find
by CukiMnstr (Deacon) on May 26, 2003 at 16:42 UTC
    You don't see any difference when changing the no_chdir parameter because you are just printing $File::Find::name which is the full path of the file, and no_chdir does not change that. If you print $_ instead, you can see the difference: with no_chdir set to 1, the filename will be relative to the directory you specified for find() to begin the search (since it will not change dirs as it traverses the filesystem tree). If no_chdir is set to 0, then find() will chdir into dirs as it traverses the tree, giving you the filename (relative to that file's directory) in $_.

    The no_chdir option isn't what you want to implement GNU find's maxdepth, check Aristotle's reply to this thread instead.

    hope this helps,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-07-31 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls