James Kipp wrote:
> Steve's suggestions worked great for ignoring or not recursing
> directories, but I am unable to filter out all directories not named
> "My Documents" . I have tried using regex and grep to filter them out
> but no luck
>
> this fails, just goes to the root directory and exits, and the docs
> really don't say
> how the preprocess option works :
>
> find {
>     preprocess => sub { grep( /My\s+Documents/, @_) },
>     wanted     => sub { print "$File::Find::name\n"}
> }, 'c:/test2';

Firstly don't forget that Windows treats the 'My Documents' directory
as a special case. Windows Explorer shows it at the same tree level
as My Computer and Recycle Bin, and it has no disk device associated
with it. Fortunatley Fil::Find will find it in '/', whichever disk drive
happens to be the current one.

Secondly, the preprocess routine is called with $File::Find::name set
to the current directory being processed, while @_ holds the names
of all files and directories contained here. The idea is that you must
return the subset of @_ in which you are interested: File::Find will
continue to process only those files which remain. (This means that
excluded files will not be passed to the wanted routine, and
excluded directories will be removed from the directory tree.

What you need to do then, is to include all of those files where
'My Documents' is in either $File::Find::name or @_. One way
to do this is to write:

    preprocess => sub {
        ($File::Find::name =~ m(/My Documents\b)
            ? @_
            : grep { $_ eq q(My Documents) } @_
        )
    },

However, having said all that, the best solution to this
particular problem is:

    find {
        wanted     => sub { print "$File::Find::name\n"}
    }, '/My Documents';

unless you have a 'My Documents' directory beneath C:/test2?

HTH,

Rob







-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to