File::Find

H

hendedav

Gang,

I am having problems passing an array of directories to find. If
I generate the array manually the code works flawlessly. If I let the
application create the array, it bombs with errors "can't stat ...:
invalid argument" even though both show the same results. Here is the
snipet of code:


both $params{'include'} and $params{'exclude'} have values like: "/
somedir/child|/anotherdir/etc|/dir/sub" with the "|" character
seperating the directories.


if (defined $params{'include'}) { (@include) = split(/\|/,
$params{'include'}); } else { return 1; } # seperate all the
"include" directories and files into an array
if (defined $params{'exclude'}) { @exclude = split(/\|/,
$params{'exclude'}); } # same for the "excluded" ones
for (my $i=0; $i<$#include+1; $i++) { # remove the preceeding /
from the entries in the include array
$include[$i] =~ s/\///;
print "$i is '$include[$i]'\n";
}

# if the below are uncommented and run, the application works
#$include[0] = "Webpage\ Projects/foo.ver4";
#$include[1] = "Webpage\ Projects/foobar";

find (sub {
if (-d "$_") { return 1; } # if the value IS a directory, then
skip to the next one

if (int(-M $_) >= $totaldays) { print " removing $_\n"; }
}, @include); # traverses the directory structure to find
files to be removed (might need to use "unlink $File::Find::name;")
}

Any help would greatly be appreciated.

Thanks,
Dave
 
H

hendedav

Gang,

I am having problems passing an array of directories to find. If
I generate the array manually the code works flawlessly. If I let the
application create the array, it bombs with errors "can't stat ...:
invalid argument" even though both show the same results. Here is the
snipet of code:

both $params{'include'} and $params{'exclude'} have values like: "/
somedir/child|/anotherdir/etc|/dir/sub" with the "|" character
seperating the directories.

if (defined $params{'include'}) { (@include) = split(/\|/,
$params{'include'}); } else { return 1; } # seperate all the
"include" directories and files into an array
if (defined $params{'exclude'}) { @exclude = split(/\|/,
$params{'exclude'}); } # same for the "excluded" ones
for (my $i=0; $i<$#include+1; $i++) { # remove the preceeding /
from the entries in the include array
$include[$i] =~ s/\///;
print "$i is '$include[$i]'\n";
}

# if the below are uncommented and run, the application works
#$include[0] = "Webpage\ Projects/foo.ver4";
#$include[1] = "Webpage\ Projects/foobar";

find (sub {
if (-d "$_") { return 1; } # if the value IS a directory, then
skip to the next one

if (int(-M $_) >= $totaldays) { print " removing $_\n"; }
}, @include); # traverses the directory structure to find
files to be removed (might need to use "unlink $File::Find::name;")

}

Any help would greatly be appreciated.

Thanks,
Dave



After continuing to play with the code, I figured out that the values
passed to find can NOT contained escaped characters. For example the
parent directory that was being passed contained two words seperated
by a space (Webpage Projects), but the automatically build array was
storing as "Webpage\ Projects". As soon as I removed the \ character,
it worked just fine. I am posting this as a followup for anyone that
may have this same problem in the future.

Dave
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top