On Jul 3, 2006, at 16:07, Dark A. wrote:
overwritten, giving the user the choice to say yes or decline to
overwrite.
That sounds like a good description of what you want. Now you need
to make predictions of exactly what should happen, so you can be sure
everything is working. For example, if you start with ‘a’, ‘b’, ‘c’,
‘d’, then you want to say ‘y,n,y,n’ to the ‘move?’ question, then you
should end up with ‘a’, ‘c’ at the end of the first section. That’s
something you can easily verify.
So, I think one problem is the destdir is continuing to
loop even after pics2bmoved is exhauster. Or something like that :).
Perhaps my next step would be to somehow combine both sections into
one.
Hmm. This strikes me as a possible misunderstanding of how nested
loops work. The inner loop (pics2bmoved.each in this case) is
executed once for every element in the outer loop (destdir.each). In
a simpler example:
a = [‘a’, ‘b’, ‘c’]
b = [1, 2, 3]
a.each do |letter|
b.each do |number|
puts “#{letter}, #{number}”
end
end
prints the following:
a, 1
a, 2
a, 3
b, 1
b, 2
b, 3
c, 1
c, 2
c, 3
In other words, when you finish the inner loop, it does the next
iteration of the outer loop, which restarts the inner loop again (and
again…).
Note that if you change the ‘puts’ to a push onto some array, you
could end up with multiple copies of whatever you’re pushing:
a = [‘a’, ‘b’, ‘c’]
b = [1, 2, 3]
c = []
a.each do |letter|
b.each do |number|
c.push(letter)
end
end
c => [‘a’, ‘a’, ‘a’, ‘b’, ‘b’, ‘b’, ‘c’, ‘c’, ‘c’]
Which seems similar to what I guessed your problem might be. Are you
creating pics2bmoved in a similar sort of nested loop?
Best of luck,
matthew smillie.