Thursday, July 24, 2014

#1 2003-02-15 11:57:49 pm

General
Member
From: Texas
Registered: 2005-08-08
Posts: 944
Website

dealing with files that arnt there

Applescript:

copy (read the file "Macintosh HD:Applications:Read Me") to thisfile

if it dosnt exist then
else
display dialog this file

lets say i wanted to load this file, and read its contents, but if it dosnt exist i want to be able to skip whats next


General

Offline

 

#2 2003-02-16 12:20:55 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: dealing with files that arnt there

You might be able use a "try / on error' statement in your script, something like this...

lets say i wanted to load this file, and read its contents, but if it dosnt exist i want to be able to skip whats next

Applescript:

try
--your script goes here
       else
       error
   end if
on error number error_number
   if the error_number is -128 then error number -128
   beep
end try

Hope this helps?


One mans trash is another mans treasure

Offline

 

#3 2003-02-16 06:43:48 am

julifos
Administrator
From: MalasaƱa, Madrid
Registered: 2002-11-20
Posts: 2014

Re: dealing with files that arnt there

In this particular situation you might check first for file's existence, because if you try to "read" the file, you must before "open for access" this file and, if it does not exist, it will be created on-the-fly. It will throw a different error "end of file error" when you attempt to read it, and you'll have a new file created every time it doesn't exist...
I'd follow this way:

Applescript:

try
   set x to alias "HD:Users:j:desktop:file.txt" --> throw error if it doesn't exist

   set z to (open for access x without write permission)
   set k to (read z)
   close access z
   
on error
   --> doesn't exist
end try

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.065 seconds, 9 queries executed ]

RSS (new topics) RSS (active topics)