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:
September 2: Social Gathering
Next Installfest:
Sat. Sept. 27, 10am-6pm
Latest News:
Aug. 30: September Installfest scheduled
Page last updated:
2003 Jul 01 16:42
Events
 Meetings
 Installfests
 Demos
 Photos
Services
 Library
 LERT
 Jobs
 Documents
Interact
 Mailing Lists
 - Search
 - Archives
 Chat
About Us
 Members
 Projects
 Testimonials
 Call for Speakers
 Why Not MS?
 Finances
 Sponsors

^Home
?Search
?News & RSS
?Calendar
@Contact Us
$Buy Stuff
=Printable


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



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

CD Burns Wanted!

LUGOD: Linux Users' Group of Davis
1105 Kennedy Place, Suite 1, Davis, CA 95616
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:
California Computer News
Who donated books and ad space.