• 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: Joe Klemmer <email@hidden>
  • Date: Fri, 02 Jul 2004 13:04:25 -0400
  • Organization: Unix System/Network Administrator & Ad Hoc Programmer

On Thu, 2004-07-01 at 13:40, Laine Lee wrote:

> > 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.
>
> Here's one way, assuming you use OS X and TextEdit is in your Applications
> folder.

This might be a little cleaner (assuming you have set your shell to
bash)...

do shell script "[ -f <yourfilename> ]" # this will return true #
if the file exists and
# is a regular file

do shell script "[ -s <yourfilename> ]" # this will return true
# if the file exists and
# is a regular file that
# is not an empty file.

You can also do negative logic by adding a "!" in front of the switch,
like -

do shell script "[ ! -f <yourfilename> ]" # this will return true
# if the file DOESN'T
# exist

--
Joe Klemmer <email@hidden>
Unix System/Network Administrator & Ad Hoc Programmer
_______________________________________________
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.


  • Follow-Ups:
    • Re: How to Test for a file ...
      • From: Emmanuel <email@hidden>
    • Re: How to Test for a file ...
      • From: Jakub Formanek <email@hidden>
References: 
 >Re: How to Test for a file ... (From: Laine Lee <email@hidden>)

  • Prev by Date: Re: Sorry
  • Next by Date: Re: control of "Desktop & Screen Saver"
  • Previous by thread: Re: How to Test for a file ...
  • Next by thread: Re: How to Test for a file ...
  • Index(es):
    • Date
    • Thread