l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
August 5: Social gathering
Next Installfest:
TBD
Latest News:
Jul. 4: July, August and September: Security, Photography and Programming for Kids
Page last updated:
2003 Jul 01 16:42

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Another Perl Question: File::Find module notworking as expected
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Another Perl Question: File::Find module notworking as expected



--On Tuesday, July 01, 2003 15:30:49 -0700 Richard Crawford <rscrawford@mossroot.com> 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 Kherron@newsguy.com 916-366-7338
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.