• 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: Checking 2 folders and copy if new
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking 2 folders and copy if new


  • Subject: Re: Checking 2 folders and copy if new
  • From: Lachlan Deck <email@hidden>
  • Date: Tue, 14 May 2002 13:33:37 +1000

Hi there,

From: Bjorn Van Blanckenberg <email@hidden>

Need to check the file in a folder on our server and compare it with a
folder on local machine

If the file doesn't exist on the local machine -> copy it

If the file exist check modification date and if it is newer copy it to the
local machine

Note: the following script contains no error checking.
All you'd need to do is add in a check to see if either folder doesn't exist before using the method handlers.

The following script allows you to either sync in both directions or in one direction.

cheers,

Lachlan Deck.

=======================
property folderOne : (path to desktop as string) & "TESTF"
property folderTwo : (path to desktop as string) & "TEST2"

on run
sync_folders(folderOne, folderTwo, false)
end run

on sync_folders(fromF, toF, both_ways)
set theItems to sync_folders_aux(fromF, toF)
if theItems is not equal to {} then
copy_files(fromF, toF, theItems)
end if
if both_ways is not equal to false then
set theItems to sync_folders_aux(toF, fromF)
if theItems is not equal to {} then
copy_files(toF, fromF, theItems)
end if
end if
end sync_folders

on copy_files(fromF, toF, theList)
set thePath to (POSIX path of fromF) as string
set theStr to "cd " & thePath & "; cp"
repeat with i from 1 to the number of items in theList
set theStr to theStr & " " & ((item i of theList) as string)
end repeat
set theStr to theStr & " " & ((POSIX path of toF) as string)
do shell script theStr
end copy_files

on sync_folders_aux(fromF, toF)
set srcItems to {}
tell application "Finder"
set list_one to (list folder fromF as alias)
set list_two to (list folder toF as alias)
repeat with i from 1 to number of items in list_one
set this_item to (item i of list_one) as string
if list_two does not contain this_item then
set the end of srcItems to this_item
else
set f1 to (folderOne & this_item) as alias
set f2 to (folderTwo & this_item) as alias
set mod1 to (modification date of f1)
set mod2 to (modification date of f2)
if mod1 is greater than mod2 then
set the end of srcItems to this_item
end if
end if
end repeat
end tell
return srcItems
end sync_folders_aux

=================================

--

thanks

Bjorn Van Blanckenberg

with regards,

--
Lachlan Deck
email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Briskets (perl)
  • Next by Date: Program Linking
  • Previous by thread: Checking 2 folders and copy if new
  • Next by thread: Re: Checking 2 folders and copy if new
  • Index(es):
    • Date
    • Thread