• 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: Andrew Oliver <email@hidden>
  • Date: Thu, 14 Apr 2005 10:25:25 -0700

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. I've got the move
> working, but I can't seem to figure out how to check if the folder
> actually has anything in it.
>
> Any assistance will be showered with gratitude and heart-felt
> ego-stroking.

Two approaches come to mind.

1) Check the folder contents:

 tell application "Finder"
   if (count files of folder "path:to:folder:") > 0 then
      -- there are files there, so move them
       move every file of folder "path:to:folder:" to folder "path:to:dest:"
   end if
 end tell

2) 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 runnning.

Andrew
:)

 _______________________________________________
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

  • Follow-Ups:
    • Re: Check to see if folder contains items?
      • From: Christopher Nebel <email@hidden>
References: 
 >Check to see if folder contains items? (From: Neil Lee <email@hidden>)

  • Prev by Date: Check to see if folder contains items?
  • Next by Date: Re: Check to see if folder contains items?
  • Previous by thread: Check to see if folder contains items?
  • Next by thread: Re: Check to see if folder contains items?
  • Index(es):
    • Date
    • Thread