How to exclude action of Find::Find::find in subdirectories withknown names?

V

vdvorkin

I must pass through directory tree and to execute some action with
files, names of which described by regex. I need not do it in
directories SCCS and VVS, which can be in every subdirectory.

The following code works correctly, does not action ("THE ACTION") in
unwanted directories, but it pass through every subdirectory. I'd
would like that it will worked faster, and procedure "wanted" will not
step inside SCCS and VVS. I have tried for that purpose the
"untaint_pattern" and "untaint_skip" options but did not success.
Perhaps I used incorrect values. Or, I do not understand the task of
the options correctly.

Somebody can suggest to me the decision?

Thanks in advance,
--Vadim

use File::Find;
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '.');

sub wanted { # $_ is file name
if ($dir !~ /\/SCCS\b/ && $dir !~ /\/VVS\b/)
{
THE ACTION...
}
}
 
J

J. Gleixner

vdvorkin said:
I must pass through directory tree and to execute some action with
files, names of which described by regex. I need not do it in
directories SCCS and VVS, which can be in every subdirectory.

The following code works correctly, does not action ("THE ACTION") in
unwanted directories, but it pass through every subdirectory. I'd
would like that it will worked faster, and procedure "wanted" will not
step inside SCCS and VVS. I have tried for that purpose the
"untaint_pattern" and "untaint_skip" options but did not success.
Perhaps I used incorrect values. Or, I do not understand the task of
the options correctly.

Somebody can suggest to me the decision?

Thanks in advance,
--Vadim

use File::Find;
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '.');

sub wanted { # $_ is file name
if ($dir !~ /\/SCCS\b/ && $dir !~ /\/VVS\b/)
{
THE ACTION...
}
}

Try the preprocess method. From the documentation: "...The code
can be used to sort the file/directory names alphabeti-
cally, numerically, or to filter out directory entries based on
their name alone. "
 
J

Jim Gibson

vdvorkin said:
I must pass through directory tree and to execute some action with
files, names of which described by regex. I need not do it in
directories SCCS and VVS, which can be in every subdirectory.

The following code works correctly, does not action ("THE ACTION") in
unwanted directories, but it pass through every subdirectory. I'd
would like that it will worked faster, and procedure "wanted" will not
step inside SCCS and VVS. I have tried for that purpose the
"untaint_pattern" and "untaint_skip" options but did not success.
Perhaps I used incorrect values. Or, I do not understand the task of
the options correctly.

Somebody can suggest to me the decision?

Set the $File::Find::prune variable when you first visit an unwanted
directory, and don't specify the 'bydepth' option (untested):

use File::Find;
sub wanted;

find( {wanted => \&wanted}, '.');

sub wanted
{
if ( m{ / SCCS \z }x || m{ / VVS \z }x )
{
$File::Find::prune = 1;
}else{
# THE ACTION...
}
}
 
V

vdvorkin

Thanks a lot, J. Gleixner and Jim Gibson. The both ways are working
correctly.

--Vadim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top