user982124
user982124

Reputation: 4622

AppleScript - exclude certain files when duplicating a folder from one location to another

I have an AppleScript that is working to duplicate the contents of a source folder to a destination folder. I now need to add some conditional logic to this so that it excludes certain files from the source folder and doesn't copy across all files/folders.

Here's my current script:

set here to POSIX file "/Users/benny/Desktop/Projects/Source/Project1"
set there to POSIX file "/Users/benny/Documents/Masters"

tell application id "com.apple.Finder" to duplicate ¬
             every item in the folder here to there

I would like to add some logic so that it doesn't copy across these files:

Import.log
Recover.log

Haven't tried to get the syntax working here but haven't been able to work out how to exclude files by their filename so far.

Upvotes: 0

Views: 167

Answers (1)

user3439894
user3439894

Reputation: 7555

The duplicate command is wrapped in a try statement because it will error out if items of the same name already exist in there. You could uncomment the with replacing and get rid of the try statement, that is if replacing an existing item is okay.

set here to POSIX file "/Users/benny/Desktop/Projects/Source/Project1"
set there to POSIX file "/Users/benny/Documents/Masters"

tell application id "com.apple.Finder"
    set theseItems to a reference to ¬
        (items whose name is not equal to "Import.log" and ¬
            name is not equal to "Recover.log") of folder here
    try
        duplicate theseItems to there -- with replacing
    end try
end tell

Upvotes: 1

Related Questions