Re: Loops
Re: Loops
- Subject: Re: Loops
- From: "J. Stewart" <email@hidden>
- Date: Fri, 1 Feb 2008 17:03:24 -0500
On 2/1/08 at 8:22 AM, Michael <email@hidden> spake thusly:
I guess in my case, it **may??** be different..but maybe not. I
was using RB to compose and write the App that searches, asks
for user input etc. Then, when a list of files ( emails) are
defined, I simply ran a loop sending AS commands ( each
specifically composed for a particular file/email) to move that
e-mail. The result was really hit and miss. Sometimes the
emails were moved, sometimes only part of the list was moved,
and if the list was really big ( artificially made so my me to
test the program) it often just failed after say 10 or 20 of a
12,000 list of emails. I was also not that tuned into the
finer details of AS that I could adequately troubleshoot
it...but I think your explanation has helped. ( You said at
one point you slowed down a loop by inserting a one second delay.)
I'm guessing but it sounds like you coded an incrementing loop
to do your move.
tell application "Finder"
set y to count (files of somefolder)
repeat with x from 1 to y -- incrementing loop
move file x of somefolder to someotherfolder
end repeat
end tell
Which is a common mistake and one almost guaranteed to catch out
a scripter from time to time.
If this is the case simply change your code to reverse the
direction of the loop, instead of incrementing, decrement the
loop variable.
Like so -
repeat with x from y to 1 by -1 -- decrementing loop
When you move files by counting up the files get reordered after
each move. i.e. you will never have a folder that contains files
with a file count that starts with anything other than 1. So it
follows that:
File 1 gets moved, file 2 now becomes file 1.
The loop iterates and the loop variable gets set to 2
What was originally file 3 gets moved as it's now file 2. The
original file 2 is bypassed.
This continues until eventually you run out of files before the
loop would normally end and Applescript throws an error because
it's looking for file x which isn't there, it's been reordered.
When you move files by counting down they don't get reordered.
J
--
The views expressed here do not necessarilly represent the
unanimous view of all parts of my mind.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
References: | |
| >Re: Loops (From: Michael <email@hidden>) |