--On Tuesday, July 01, 2003 15:30:49 -0700 Richard Crawford <[EMAIL PROTECTED]> wrote:

The following script addresses the problem I had earlier of moving files
from a Windows computer to a Unix server when the directory structures
are different.  Within each subfolder on the Unix server there is a
directory called "messages".  For some reason, it seems that File::Find
is not traversing the directory tree properly and going into the
messages folder at all.

It looks like you expect move() to be called once per directory. In fact it will be called for every file and directory encountered under $start_dir. For example, if $start_dir contains five files and a subdirectory with three more files, then find is going to call move() nine times; six times in $start_dir and three in the subdirectory.


I suspect the immediate problem is that you're creating and deleting files within the directories you're traversing. This may be causing some reorganization within the directory, leading to readdir() skipping some files.

Let me suggest the function called by find() should just store each name of interest in a global array or hash. Once the find() is finished you can iterate through the array. Assuming you only want to call move once per directory, something like the following would get you started:

        my @dirs;
        sub wanted { push @dirs, $File::Find::Name if (-d $_) }
        find \&wanted, $start_dir;
        move($_) foreach (@dirs);

--
Kenneth Herron  [EMAIL PROTECTED]     916-366-7338
_______________________________________________
vox-tech mailing list
[EMAIL PROTECTED]
http://lists.lugod.org/mailman/listinfo/vox-tech

Reply via email to