Re: Strange behaviour of file from list after renaming...
Re: Strange behaviour of file from list after renaming...
- Subject: Re: Strange behaviour of file from list after renaming...
- From: John Stewart <email@hidden>
- Date: Thu, 15 Jul 2004 13:29:55 -0400
On 07/14/04 at -0600 David Crowe said this
>
Normally it is quite possible to cast a file to a string.
>
>
For example, something like: tell Application "Finder" to set
>
FileList to every file in folder SomeName whose name starts with "A"
>
>
>
You can then access the list as: repeat with AFile in FileList
yes
>
>
>
At this point "Afile as string" is valid and contains the full path
>
name of the file.
In this particular instance it does.
Here's a good place to stop and think. I suspect you are assuming because you
get the result you expect (a string containing the file's path) that you think
"afile" contains the value of the list item i.e. a reference to a file. It
doesn't! Further more, using "afile" in the manner you are using it will not
always work, it's dependent on what the actual data in the list item is. As
used "afile" contains a reference to a list item and that list item contains
your file's reference. Think "silent coercion that can really send you down the
garden path" here. Check out the "Repeat with (loop Variable) In (list)"
section on page 256 of the ASLG for AS 1.3.7
Given a list
repeat with anum in {1,2,3}
On the first iteration through the list "anum" will contain "item 1 of
{1,2,3}", it does not contain the actual value (1) of list item 1.
>
However, if you rename the file: set name of AFile to StringContainingNewName
>
>
.... then it is no longer possible to convert "AFile" to a string.
>
Because "afile" is a reference to a list item and not the item's value. You
would need to change the item's value in the list for the reference to regain
validity. The easy way is to use a list of aliases instead of file references
because aliases track the original file even through a name change.
>
This is very useful to keep track of files that are open in my
>
current application.
>
>
Is there another way to get a string encoding the entire file
>
pathname? Am I doing something wrong in my method of accessing the
>
file information?
Perhaps if you explained exactly what you are trying to do we could offer more
help.
JBS
--
A truly wise man never plays leapfrog with a Unicorn.
JBS
--
There are two major products that come out of Berkeley: LSD and UNIX. B We don't
believe this to be a coincidence. B - Jeremy S. Anderson
_______________________________________________
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.