• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to Test for a file ...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to Test for a file ...


  • Subject: Re: How to Test for a file ...
  • From: Walter Ian Kaye <email@hidden>
  • Date: Wed, 30 Jun 2004 14:09:48 -0700

At 01:24p -0700 06/30/2004, Charles Heizer didst inscribe upon an electronic papyrus:

I was wondering if anyone could tell me how to test if a file exists? So, if it does not I can create the file.

There are at least two ways:

set fileLoc to (path to "asup") as string
set fileName to "foo"

tell application "Finder"
if not exists file (fileLoc & fileName) then
make new file at folder fileLoc with properties {name:fileName}
end if
end tell

try
alias (fileLoc & fileName)
on error
open for access file (fileLoc & fileName) with write permission
close access result
end try


Note that using the Finder to create a file will automatically give the file a "blank" resource fork (286 bytes), whereas the osax file command will not.


-Walter
"quoth the raven: livermore"
_______________________________________________
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.


References: 
 >How to Test for a file ... (From: Charles Heizer <email@hidden>)

  • Prev by Date: Re: How to Test for a file ...
  • Next by Date: two files...
  • Previous by thread: Re: How to Test for a file ...
  • Next by thread: two files...
  • Index(es):
    • Date
    • Thread