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: Axel Luttgens <email@hidden>
- Date: Thu, 15 Jul 2004 09:39:56 +0200
David Crowe wrote:
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
At this point "Afile as string" is valid and contains the full path
name of the file.
However, if you rename the file: set name of AFile to
StringContainingNewName
... then it is no longer possible to convert "AFile" to a string.
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?
I'll first try to reduce your description to its basics, so as to be
sure we are speaking about the same thing ;-)
Assuming I have a folder "test" on the desktop, that folder containing a
file "Atest":
tell application "Finder"
set L to every file of folder "test" whose name starts with "A"
set F to item 1 of L
--> {document file "Atest" of folder "test" of folder "Desktop"
of folder "luttgens" of folder "Users" of disk "Data"}
F as string
--> "
Data:Users:luttgens:Desktop:test:Atest"
set name of F to "Btest"
F as string
--> Impossible de designer +class docf; "Atest" of +class cfol;
"test"
of +class cfol; "Desktop" of +class cfol; "luttgens" of
+class cfol;
"Users" of +class cdis; "Data" of application "Finder"
comme string.
end tell
The error message tends to show that F constitutes a name reference form.
That is, when encountering F, the Finder really expects to find a file
named "Atest" to act upon.
So, you could avoid subsequent errors by updating the reference
immediately after the name change:
tell application "Finder"
set L to every file of folder "test" whose name starts with "A"
set F to item 1 of L
F as string
set name of F to "Btest"
set F to file "Btest" of folder "test"
F as string
end tell
On the other hand, this could also be a job for aliases instead of
Finder references:
tell application "Finder"
-- possibly not the best way to handle the single-item case,
-- but it works :-)
try
set L to (every file of folder "test" whose name starts with
"A") as alias list
on error
set L to {(every file of folder "test" whose name starts
with "A") as alias}
end try
set F to item 1 of L
F as string
--> "
Data:Users:luttgens:Desktop:test:Atest"
set name of F to "Btest"
F as string
--> "
Data:Users:luttgens:Desktop:test:Btest"
end tell
HTH,
Axel
_______________________________________________
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.