Shawn Corey <[EMAIL PROTECTED]> writes:

> When File::Find goes looking for files, it chdir's to each directory
> its looking in. When it's in ./dir1, there is no ./dir1/tmp to copy
> files into, so you get an error. Change your calling sequence of
> find() to:
>
>   find( { wanted => \&wanted, no_chdir => 1, }, @searchdir);
>
> See `perldoc File::Find` for details.

Thanks, I had figured out something kind of close as posted a bit
ago.  I like the looks of your solution (but haven't tried it yet.

I went a different way before seeing your post and hit another snag.

I decided to just scrap File::Find in favor of chdir opendir and
readdir.  I think the File::Copy has a problem when the left file
name  has a directory name in it.

But leaving that a moment, I can't see why this for loop doesn't 
print any content for dir2.

dir1 and dir2 are just copies of each other. They contain the exact
same files.  They are files with numeric names.

Perhaps that is why.. same file ionode?

I just used @fname as a counter here just to demonstate what I'm
seeing. Also the regex is just a place holder for demo.

#!/usr/local/bin/perl -w

@directories = ("./dir1", "./dir2");

for(@directories) {
  opendir(WRK_DIR,"$_");
  chdir $_;
  print "hpdb thisdir=<$_>  \n";    

  @fnames = grep { /\d/ } readdir(WRK_DIR);
  closedir(WRK_DIR);
  print "$_ has <" . @fnames> . "> files\n";
}

The output puzzles me:

  hpdb thisdir=<./dir1>  
  ./dir1 has <57> files
  -- 
  hpdb thisdir=<./dir2>  
  ./dir2 has <0> files

dir2 is not empty ... its a copy of dir1

Now if I comment out the `chdir' line:
I get the expected results.  (I don't understand why)

  hpdb thisdir=<./dir1>  
  ./dir1 has <57> files
  -- 
  hpdb thisdir=<./dir2>  
  ./dir2 has <57> files




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to