Re: Check to see if folder contains items?
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