Re: This AppleScript stuff is harder than I thought
Re: This AppleScript stuff is harder than I thought
- Subject: Re: This AppleScript stuff is harder than I thought
- From: Andrew Oliver <email@hidden>
- Date: Fri, 17 Jun 2005 14:05:18 -0700
On 6/17/05 1:17 PM, "Sparky" <email@hidden> wrote:
> I've spent the good part of a day trying to write what I THOUGHT
> would be a very simple script. All I want to do is make a copy of a
> folder -- the trick is that I want those items in the source with
> specific names to be filtered out. Is this so hard? But I find myself
> swimming in details and errors. Can't the Finder be coerced into
> doing this easily?
There are ways of duplicating a folder in the way you say, making sure some
files are not copied, but it's actually far easier to duplicate the entire
folder, then eliminate the files in question:
--- BEGIN SCRIPT ---
property unwantedFiles: {"file1.txt", "file2.jpg", "file3.xml"}
tell application "finder"
set newFolder to duplicate folder "path:to:original:folder" to folder
"path:to:copy"
-- now you have a newFolder that matches the original folder
-- so delete the unwanted files
repeat with filename in unwantedFiles
try
delete file filename of folder newFolder
end try
end repeat
end tell
--- END SCRIPT ---
Here the entire folder is copied, then the script loops through the unwanted
filenames deleting them as it goes. Putting the 'delete' in a try block
takes care of cases where the unwanted files didn't exist to start with.
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