Re: Determining If a File Exists
Re: Determining If a File Exists
- Subject: Re: Determining If a File Exists
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 11 Mar 2004 09:05:29 -0800
On 3/11/04 8:25 AM, "Marconi" <email@hidden> wrote:
>
Here's a snippet:
>
>
set fileName to name of the item_info
>
set OldFile to (targetFolder & fileName) as text
>
if file OldFile exists then
>
display dialog OldFile & " already exists."
>
end if
>
>
>
targetFolder is the path to a folder, so oldFile is a full path to a
>
particular file (that may be) in the folder.
You just set OldFile 'as text' . Is 'targetFolder' also a string, or is it
a folder object? Concatenating a folder object with a string would create a
list. If it's a folder object then you'd need to do:
set OldFile to ((targetFolder as string) & fileName)
first. Or, better in OS X:
set OldFile to ((targetFolder as Unicode text) & fileName)
Let's suppose it's a string or Unicode text. Then you have to put the
'exists' command into a Finder tell block, otherwise it's meaningless:
tell app "Finder"
if exists file OldFile
etc. There have been a few issues with the 'file' keyword, but outside
Finder blocks not inside them , except that Finder 'file' objects don't
really take colon filePaths, you know. they take 'file "A" of folder "B"
etc. They do take filePaths OK with 'alias'. But if you're using 'alias',
you don't really need the Finder at all. Use a try block instead:
try
get alias OldFile
-- rest of script, or set a boolean to true
on error
--error message or set a boolean to false
end try
if theBoolean then
--rest of script
end if
>
>
The error message I get is that [actual full path name] doesn't
>
understand 'exists'
--
Paul Berkowitz
_______________________________________________
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.