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

Discussion in 'Perl Misc' started by vdvorkin, Feb 10, 2011.

  1. vdvorkin

    vdvorkin Guest

    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...
    }
    }
    vdvorkin, Feb 10, 2011
    #1
    1. Advertising

  2. vdvorkin

    J. Gleixner Guest

    vdvorkin wrote:
    > 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. Gleixner, Feb 10, 2011
    #2
    1. Advertising

  3. vdvorkin

    Jim Gibson Guest

    Re: How to exclude action of Find::Find::find in subdirectories with known names?

    In article
    <>,
    vdvorkin <> wrote:

    > 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...
    }
    }

    --
    Jim Gibson
    Jim Gibson, Feb 10, 2011
    #3
  4. vdvorkin

    vdvorkin Guest

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

    --Vadim
    vdvorkin, Feb 14, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thieum22
    Replies:
    1
    Views:
    660
    Joe Smith
    Aug 6, 2004
  2. Joe Bloggs
    Replies:
    1
    Views:
    726
    Sudsy
    Aug 3, 2003
  3. rjweytens
    Replies:
    6
    Views:
    16,051
    rjweytens
    Jun 25, 2004
  4. lucy
    Replies:
    6
    Views:
    147
    Michele Dondi
    Sep 3, 2004
  5. vdvorkin
    Replies:
    0
    Views:
    389
    vdvorkin
    Feb 10, 2011
Loading...

Share This Page