On Monday 01 Mar 2010 13:23:16 raphael() wrote:
> Hi,
> 
> How can I stop File::Find to go below current dir? i.e. no recursion.
> 
> Although I can use glob or <*> to get file names in current dir.
> But I wanted to know if File::Find has a maxdepth limit like linux "find".
> 

Not, by itself, but there are wrappers around it that provides you with it. 
And there are several alternative modules like File-Find-Object or File-Next 
that solve some of its inherent philosophical limitations. For a summary see:

* http://www.shlomifish.org/open-source/projects/File-Find-Object/

* http://www.perlfoundation.org/perl5/index.cgi?alternatives_to_file_find

> The script I created uses a switch which decides if recursion is allowed or
> not.
> It uses the system find like this..
> 
> open(FIND, "find -maxdepth $recursive |" );
> 
> I wanted to remove this dependency on system find. Is it possible with
> File::Find?

It is possible.

> 
> I tried this after googling
> 
> http://www.perlmonks.org/?node_id=676958
> 
> sub wanted
> {
>     if ( -d ) { # should I write this as -d $File::Find::name
>           $File::Find::prune = 1;
>           return;
>     }
>     print $File::Find::name . "\n";
> }

Well, this will only be equivalent to -maxdepth 1 not to larger values. I 
can't tell you offhand whether it's "-d $_" or "-d $File::Find::name" because 
the File::Find interface is evil-incarnate and I'm trying to forget it. If you 
want to prune after an arbitrary maxdepth, you'll need to keep track of the 
current depth and the level there. May be File::Find gives you that but you 
really should be using File::Find::Object, File::Find::Rule or 
File::Find::Object::Rule .

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
What does "Zionism" mean? - http://shlom.in/def-zionism

Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to