2 Replies Latest reply: Apr 28, 2012 11:49 AM by Pierre L.
gexooo Level 1 Level 1 (0 points)

Hey,

 

how can i  compare files with apple script? I wrote a script wich will copy files from my local MBP to my AFP-Share. Now i want my script to copy files which modified-date is younger, so that i got the latest version on my share. 

 

-- Mounting and Upload script

-- Variablen

set Net_Drive to "Share:Scripts"

set Up_Dir to "Mac OS:Users:xxx:Documents:Exchange:Upload:"

 

-- Mounting

tell application "Finder"

          try

                    mount volume "AFP://<someurl>"

          on error

                    display dialog "Mounting failed" buttons {"Ok"} with title "Action Failed"

          end try

end tell

 

-- Upload

 

tell application "Finder"

  duplicate every file of folder Up_Dir to folder Net_Drive 

end tell

 

thanks for your help

 

P.S.: i did not found any thread which could help me


MacBook Pro, Mac OS X (10.7.3)
  • Pierre L. Level 5 Level 5 (4,115 points)

    Using pure AppleScript, what you are asking for can be done as follows:

     

    tell application "Finder"

        repeat with thisFile in (get files of folder Up_Dir)

            set thisName to name of thisFile

            if file thisName of folder Net_Drive exists then

                set theOtherFile to file thisName of folder Net_Drive

                if modification date of thisFile > modification date of theOtherFile then

                    duplicate thisFile to folder Net_Drive with replacing

                end if

            end if

        end repeat

    end tell


  • Pierre L. Level 5 Level 5 (4,115 points)

    Here's a slightly improved (an probably faster) version of the previous script:

     

    set volume with output muted -- optional

    tell application "Finder"

        repeat with thisFile in (get files of folder Up_Dir)

            set thisName to name of thisFile

            if (file thisName of folder Net_Drive exists) and (modification date of thisFile > modification date of file thisName of folder Net_Drive) then

                duplicate thisFile to folder Net_Drive with replacing

            end if

        end repeat

    end tell

    display dialog "Done!" buttons {"OK"} default button 1 with icon 1

    set volume without output muted