Re: Repeat Loop Skipping Items
Re: Repeat Loop Skipping Items
- Subject: Re: Repeat Loop Skipping Items
- From: "Marc K. Myers" <email@hidden>
- Date: Sat, 09 Jun 2001 09:37:54 -0400
- Organization: [very little]
>
From: Steve Suranie <email@hidden>
>
To: "'email@hidden'"
>
<email@hidden>
>
Subject: Repeat Loop Skipping Items
>
Date: Fri, 8 Jun 2001 15:53:10 -0400
>
>
Has anyone had this happened before. I am running a script that checks a
>
folder that allows the user to select a folder. The script then loops
>
through all the items of the folder and if they are a TEXT type, opens them
>
in Tex-Edit Plus and copies the contents into an existing file. The script
>
read each file sequentially just like it was designed to. Good script.
>
>
However, I then wanted to move the aforementioned read articles out of the
>
folder to a seperate folder. When I added that bit o script the script
>
continued to move sequentially through the files but in leaps of four or so.
>
It did move those files it read but as I explained to my computer in no
>
uncertain terms, that's not what it was designed to do. Bad script.
>
>
Anyway, in scripting AppleScript terms I'm a relative newbie, (a few months)
>
so I'm curious if anyone else has suffered through this and could send a
>
tip/explanation to me how to fix this? (And lets not blame the programmer,
>
right, we all know its the computer doing this) ; )
I suspect the problem derives from your using (excuse me; "the computer
using") some control on your repeat loop that changes as you move files
out of the folder. Try it this way:
set theFolder to (choose folder with prompt "Pick a folder:")
tell application "Finder"
set textFiles to (files of theFolder whose file type is "TEXT") as
alias list
end tell
repeat with aFile in theFolder
set theFile to (contents of aFile)
--> copy the contents and move theFile
end repeat
It creates a list of the text files in the folder and uses that instead
of looking at the current contents of the folder, which change as you
move files to another folder.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[6/9/01 9:36:01 AM]