Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File::Find for non recursive searching

Status
Not open for further replies.

spperl

Programmer
Mar 29, 2005
34
0
0
GB
Hi,

Hopefully someone can help here... my question is as follows:

Is there a way to configure File::Find so that it 'stays' in the top directory and does not perform a recursive search?

example of what I have that is not working?

Code:
my @fileList=();
  find ( { wanted   => sub {push @fileList, $File::Find::name if(!-d)}, no_chdir => 1 }, "/temp/");

Depending on selection my application will need to search recursively or only on the top / starting level.

Any help would be appreciated.

Thanks
 
Don't use File::Find if you only want to search one directory, Use opendir() and grep().

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I can see why you'd want to use generic code with File::Find rather than Kevin's suggestion to save writing different code for the two options.

You may find the find2perl utility useful if you are familiar with the Unix find utility and its -prune syntax, otherwise experiment with setting $File::Fine::prune = 1 at the appropriate times in your &wanted function to prevent further descent into the directory structure.

Annihilannic.
 
Another alternative is to use File::Find::Rule, which allows you to set a maxdepth option.

no_chdir isn't designed to do what you're looking for BTW.
 
You can use $File::Find::prune to prevent descending into a directory, trick is getting it to work. [wink]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top