Looping through a list with only one item problem?
Looping through a list with only one item problem?
- Subject: Looping through a list with only one item problem?
- From: "Gregory Smith" <email@hidden>
- Date: Tue, 19 Mar 2002 14:39:38 -0800
Hello,
I have written a script that performs as expected with one exception; when a
list contains only one item, the script will fail. The loop will attempt to
read each character of the single item text name instead of the single item
as a string.
Example:
When the list contains...
--BEGIN_APPLESCRIPT--
set my_File_Name_List to []
set my_File_Name_List to name of every item of folder "test" of startup disk
-- Variable returns something like ["name1","name 2","name 3"]
repeat with my_File_Name in my_File_Name_List
--result "name1" and so on
<--do routine-->
end
--END_APPLESCRIPT--
.... the loop will work as expected.
When the list is only one item....
--BEGIN_APPLESCRIPT--
set my_File_Name_List to []
set my_File_Name_List to name of every item of folder "test" of startup disk
-- Variable returns only a single file name: ["name1"]
repeat with my_File_Name in my_File_Name_List
--result "n" and so on
<--do routine-->
end
--END_APPLESCRIPT--
....in this latter case, the loop attempts to read the "t", then the "e"
then the "x" and so on as single items. The script immediately fails
because it is expecting to 'see' a file name and of course no file exists
with the name "t" or "e" at the defined path and so on.
I've tried to re-set the loop variables to be a string or text with the same
results. Even running a (count of my_File_Name_List) when only one item
exists returns the count of the item's character count instead of '1' item
as I desire.
What would be the proper way to force a single item in a list (or ?) to be
in fact a single item or is a single item list by definition NOT a list?
Stumped. Thanks for your help in advance!
--
Thanks,
Greg Smith
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.