Re: repeat problem
Re: repeat problem
- Subject: Re: repeat problem
- From: Don Thompson <email@hidden>
- Date: Tue, 25 Sep 2001 14:30:50 -0500
This is a problem that I have experienced in other environments. I *think*
it may be that as you move the items from the folder, Applescript is
becoming confused.
For instance. You start with a folder of 100 items. Your initial statement,
sets itemCount to 100. Then you instruct the loop to do something exactly
100 times.
However, the first time you move a file out of the folder, there is no
longer 100 files in the folder. It seems that Applescript is probably using
relative references, just as you are. It's trying to get the X item of this
folder, but you have removed a number of files so there is no X file of that
folder. Then you get an error.
Work arounds:
1. Create some arrays and populate them with the full paths to the files you
want to move and to where as you go through the loop. Then loop through that
array to do the actual moves.
2. Instead of moving, copy, then go back and delete.
3. Use a repeat until structure, manually count iterations, and then at the
bottom of the loop check to see if your counter exceeds the number of files
in the folder.
>
From: Steve Suranie <email@hidden>
>
Date: Tue, 25 Sep 2001 14:19:50 -0400
>
To: "'email@hidden'"<email@hidden>
>
Subject: repeat problem
>
>
Hi folks:
>
>
Can anyone give me a hint as to why this is happening:
>
>
I am using a repeat statement to go through the contents of a folder and
>
determine the file type of the files in that folder. If they match a certain
>
type I want to do one thing, if not I want to ignore them. (For now I am
>
just moving the ones I want to do something to to another folder.
>
>
I have this script:
>
>
...set itemCount to count of every item of theFolder...
>
>
...repeat with i from 1 to itemCount
>
set itemName to name of item (i) of theFolder
>
set itemType to file type of item (i) of theFolder
>
>
if itemType = "EPSF" then
>
display dialog "This is an eps file"
>
move item (i) of theFolder to folder "LogoFolder" of folder
>
"MerionRecruitmentAds"
>
else if itemType = "TIFF" then
>
display dialog "This is a tif file"
>
move item (i) of theFolder to folder "LogoFolder" of folder
>
"MerionRecruitmentAds"
>
else
>
display dialog itemName
>
end if
>
>
end repeat...
>
>
this loops fine if I do something like this
>
>
...repeat with i from 1 to itemCount
>
set itemName to name of item (i) of theFolder
>
set itemType to file type of item (i) of theFolder
>
>
display dialog itemType
>
end repeat...
>
>
but if I throw in the if statement I get an error message stating it can't
>
get the last item of folder...blah, bah, blah.
>
>
Why won't the loop work with the if statement?
>
>
Muchos grandees
>
>
Steve
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users