• 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: Check to see if folder contains items?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Check to see if folder contains items?


  • Subject: Re: Check to see if folder contains items?
  • From: Christopher Nebel <email@hidden>
  • Date: Mon, 18 Apr 2005 09:10:24 -0700

On Apr 14, 2005, at 10:25 AM, Andrew Oliver wrote:

On 4/14/05 10:14 AM, "Neil Lee" <email@hidden> wrote:

This is a total newbie question, but I haven't been able to figure out
or Google my way to a solution.


I want to check to see if a particular folder contains items, and if
so, move those items to a different location. ...

... Who cares? Use error trapping:

tell application "Finder"
try
move every file of folder "path:to:folder:" to folder "path:to:dest:"
on error
-- there was an error, presumably no files to copy
end try
end tell


The second approach relies on AppleScript's ability to catch errors in a
try/end try block, so that the move command fails, but it doesn't stop your
script from running.

In fact, you don't even need the "try" block, because the command doesn't fail, at least not for that reason -- it's not considered an error for "every" to resolve to no items. (Yes, this is documented in TN2106.)



--Chris Nebel AppleScript Engineering

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Check to see if folder contains items? (From: Andrew Oliver <email@hidden>)

  • Prev by Date: Re: Image Events
  • Next by Date: Re: Setting permission from an applescript
  • Previous by thread: Re: Check to see if folder contains items?
  • Next by thread: Re: Check to see if folder contains items?
  • Index(es):
    • Date
    • Thread