kcw | journal | 2001 << Previous Page | Next Page >>
(*
Synchronize Folder
Kevin C. Wong -- 20011209-- v 1.0b9
Synchronize destination folder to match source folder.

20011209 1.0b9
-- Add: m_date_mod. Equalizes date differences if they differ by exact hours. \
For source/dest in diff time zones.
-- Add: m_filter_long_file_names. Filter if file name > 31 characters, \
for copying from Mac OS X to Mac OS 9.
-- Bug: Comparing l_dest_item to "" instead of false to see if it's uninitializesd.

20011125 1.0b8
-- Bug: comparing l_source_kind (Unicode text) to strings sometimes errors \
with "Can't convert object..."
-- Bug: 1.0b7 overwrites m_log_file rather than appending to it.
-- Change: Always compare modification dates. Copy source modification date to destination.
-- Change: Leave m_diff_sec at 0 because previous change makes this unnecessary.

20011108 1.0b7
-- Add: m_filter_like_files to filter out Cache folders.
-- Change: Replaced hard coded \r with RET constant.
-- Fix: Use Unicode text for any strings that involve file names.
-- Bug: Sometimes alias l_current_folder can't be coaxed into Unicode text.
-- Use records instead of aliases in l_pending_folders. \
This way we can build up path as a Unicode string.
-- Also fix source folder, destination folder, deleted folder, log file for above bug.
-- Use creation date for kind "Classic Application".
-- Bug: l_source_item_name is equal to "index.html" doesn't work if l_source_item_name \
is Unicode text.

20011107 1.0b6
-- Now requires Mac OS X 10.1 which has many AppleScript fixes and enhancements.
-- Don't use "info for" since 10.1 fixed the problems "info for" worked around.
-- Removed copy invisible option because you need to get it from properties which \
also returns file size.
-- Removed addIsFolderAttribute() because we don't use it anymore.
-- Verbose logging of copy decisions.
-- Use sort of depth-first folder traversal instead of level-order folder traversal.
-- Do sync delete for each folder right after sync copy of folder.
-- Choose file name now returns <>. Change to check for m_log_file is not boolean.
-- Use creation date instead of modification date for Apps, since mod date is not \
preserved by Finder copy.
-- Finer logging control: choose from list of five attributes to log.

20011028 1.0b5
-- Add: m_diff_sec so that modification dates can differ by a few seconds. Default to 60.
-- Add: m_filter_files so that certain files can be skipped. Default to system files.
-- Add: m_copy_invisible so that invisible files can be skipped. Default to false.
-- Add: m_verbose_logging prints every file being checked.
-- Bug: Trying to copy folder items if destination folder wasn't created because \
file name is illegal.
-- Add: m_error_logging for suppressing error and filter logging.

20011026 1.0b4
-- Use "list folder" instead of "get items of folder alias". Then use file specifications
instead of actual files, use "info for " to get most if item info we need. These changes
work with applications and invisible items, which didn't work with "get items of folder alias".
Lots of little changes to support the new mechanism.

20011025 1.0b3
-- Bug: No date by comparison if m_copy_newer_files_only is false
-- Fix: Delete or move non-folder file before we create folder to replace it.
-- Fix: Close m_log_file when done.
-- Fix: Close m_log_file before opening it again in case it's already open.
-- Fix: Test for log write should be "class of m_log_file is file specification".
-- Fix: Start writing to log file at the end of the file, not the beginning.
-- Fix: Added line endings to log output.
-- Workaround: Skip Application files.
*)

set m_source_folder to ""
set m_destination_folder to ""
set m_deleted_folder to true

set m_log_file to false
set m_log_errors to false
set m_log_actions to false
set m_log_decisions to false
set m_log_folder_trace to false
set m_log_file_trace to false

set m_copy_newer_files_only to false
set m_ignore_exact_hours to false
set m_filter_exact_files to {".DS_Store" as Unicode text, "Desktop DB" \
as Unicode text, "Desktop DF" as Unicode text, Â
"TheVolumeSettingsFolder" as Unicode text, "AppleShare PDS" \
as Unicode text, "Temporary Items" as Unicode text}
set m_filter_like_files to \
{"Cache" as Unicode text, "Trash" as Unicode text, ".FBC" as Unicode text}
set m_filter_long_file_names to false

set m_create_index2_files to false -- !!! EXTRA !!!

set m_quit to false

set RET to "
"

tell application "Finder"

-- Get source and destination folders
if (m_source_folder = "") then
try
with timeout of 86400 seconds -- 1 day timeout
set m_source_folder to choose folder with \
prompt "Items will be copied FROM this folder (Cancel to quit):"
end timeout
on error l_error
set m_quit to true
end try
end if

if (m_quit is false) then
if (m_destination_folder = "") then
try
with timeout of 86400 seconds -- 1 day timeout
set m_destination_folder to choose folder with \
prompt "Items will be copied TO this folder (Cancel to quit):"
end timeout
on error l_error
set m_quit to true
end try
end if
end if

if (m_quit is false) then
if (m_deleted_folder is true) then
try
with timeout of 86400 seconds -- 1 day timeout
set m_deleted_folder to choose folder with prompt "Deleted items will be moved \
to this folder (Cancel to delete items instead):"
end timeout
on error l_error
set m_deleted_folder to false
end try
end if

if (m_log_file is false) then
with timeout of 86400 seconds -- 1 day timeout
try
set l_choices to ""
set l_choices_string to ""

set m_log_file to Â
choose file name with prompt Â
"Write synchronize log to this file (Cancel for no logging):" default \
name "Synchronize_Folder_Log.txt"

set l_options to {"Errors", "Actions", "Decisions", "Folder Trace", "File Trace"}
set l_defaults to {"Errors", "Actions"}

set l_choices to choose from list l_options with prompt Â
"Select activities to log:" default items l_defaults with multiple \
selections allowed and empty selection allowed

if ("Errors" is in l_choices) then
set m_log_errors to true
set l_choices_string to "Errors"
end if
if ("Actions" is in l_choices) then
set m_log_actions to true
if (l_choices_string is equal to "") then
set l_choices_string to "Actions"
else
set l_choices_string to l_choices_string & ", Actions"
end if
end if
if ("Decisions" is in l_choices) then
set m_log_decisions to true
if (l_choices_string is equal to "") then
set l_choices_string to "Decisions"
else
set l_choices_string to l_choices_string & ", Decisions"
end if
end if
if ("Folder Trace" is in l_choices) then
set m_log_folder_trace to true
if (l_choices_string is equal to "") then
set l_choices_string to "Folder Trace"
else
set l_choices_string to l_choices_string & ", Folder Trace"
end if
end if
if ("File Trace" is in l_choices) then
set m_log_file_trace to true
if (l_choices_string is equal to "") then
set l_choices_string to "File Trace"
else
set l_choices_string to l_choices_string & ", File Trace"
end if
end if
on error l_error
end try
end timeout
end if

-- Should we only copy newer files?
set l_record to display dialog "Copy only if source file is newer?" buttons {"yes", "no"}
if (button returned of l_record is "yes") then
set m_copy_newer_files_only to true
end if

-- Should we consider time zones?
set l_record to display dialog "Exact hour differences are same date?" buttons {"yes", "no"}
if (button returned of l_record is "yes") then
set m_ignore_exact_hours to true
end if

-- Should we copy system files?
set l_record to display dialog "Copy system files?" buttons {"yes", "no"}
if (button returned of l_record is "yes") then
set m_filter_exact_files to {}
set m_filter_like_files to {}
end if

-- Copy files with long file names?
set l_record to display dialog "Ignore files with long names?" buttons {"yes", "no"}
if (button returned of l_record is "yes") then
set m_filter_long_file_names to true
end if

-- !!! EXTRA !!!
-- Should we create index2.html files?
set l_record to display dialog "Copy index.html to index2.html?" buttons {"yes", "no"}
if (button returned of l_record is "yes") then
set m_create_index2_files to true
end if

-- Convert m_source_folder to Unicode text, if it fails, do a lot of get name of xxx
try
set m_source_folder_string to m_source_folder as Unicode text
on error l_error
try
set l_item to m_source_folder
set l_string to ""

-- Loop until we get an error
repeat
set l_string to (get name of l_item as Unicode text) & ":" & l_string
set l_item to (get container of l_item)
end repeat
on error l_error
end try

set m_source_folder_string to l_string
end try

-- Convert m_destination_folder to Unicode text, if it fails, do a lot of get name of xxx
try
set m_destination_folder_string to m_destination_folder as Unicode text
on error l_error
try
set l_item to m_destination_folder
set l_string to ""

-- Loop until we get an error
repeat
set l_string to (get name of l_item as Unicode text) & ":" & l_string
set l_item to (get container of l_item)
end repeat
on error l_error
end try

set m_destination_folder_string to l_string
end try

-- Convert m_deleted_folder to Unicode text, if it fails, do a lot of get name of xxx
try
set m_deleted_folder_string to m_deleted_folder as Unicode text
on error l_error
try
set l_item to m_deleted_folder
set l_string to ""

-- Loop until we get an error
repeat
set l_string to (get name of l_item as Unicode text) & ":" & l_string
set l_item to (get container of l_item)
end repeat
on error l_error
end try

set m_deleted_folder_string to l_string
end try

-- Convert m_log_file to Unicode text, if it fails, do a lot of get name of xxx
if (class of m_log_file is not boolean) then
try
close access m_log_file
on error l_error
end try

try
open for access m_log_file with write permission
on error l_error
log l_error as string
log "Disabling log file..."
set m_log_file to false
end try

try
set m_log_file_string to m_log_file as Unicode text
on error l_error
try
set l_string to ""
set l_item to (get container of m_log_file)
set l_string to (get name of m_log_file)

-- Loop until we get an error
repeat
set l_string to (get name of l_item as Unicode text) & ":" & l_string
set l_item to (get container of l_item)
end repeat
on error l_error
end try

set m_log_file_string to l_string
end try
end if

-- Log start time
set l_start_time to current date
log "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
log ("Backup source: " as Unicode text) & m_source_folder_string
log ("Backup destination: " as Unicode text) & m_destination_folder_string
log ("Deleted folder: " as Unicode text) & m_deleted_folder_string
log ("Log file: " as Unicode text) & m_log_file_string
log "Log options: " & l_choices_string
log "Copy only if source is newer: " & m_copy_newer_files_only
log "Ignore exact hour differences: " & m_ignore_exact_hours
log ("Filter exact files: " as Unicode text) & m_filter_exact_files
log ("Filter like files: " as Unicode text) & m_filter_like_files
log "Ignore files with long names: " & m_filter_long_file_names
log "Copy index.html to index2.html: " & m_create_index2_files
log "Backup start time: " & l_start_time as string
log "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
if (class of m_log_file is not boolean) then
write "=============================================================" \
& RET starting at (get eof m_log_file) + 1 to m_log_file
write ("Backup source: " \
as Unicode text) & m_source_folder_string & RET to m_log_file
write ("Backup destination: " \
as Unicode text) & m_destination_folder_string & RET to m_log_file
write ("Deleted folder: " \
as Unicode text) & m_deleted_folder_string & RET to m_log_file
write ("Log file: " \
as Unicode text) & m_log_file_string & RET to m_log_file
write "Log options: " & l_choices_string & RET to m_log_file
write "Copy only if source is newer: " & m_copy_newer_files_only & RET to m_log_file
write "Ignore exact hour differences: " & m_ignore_exact_hours & RET to m_log_file
write ("Filter exact files: " \
as Unicode text) & m_filter_exact_files & RET to m_log_file
write ("Filter like files: " \
as Unicode text) & m_filter_like_files & RET to m_log_file
write "Ignore files with long names: " & m_filter_long_file_names & RET to m_log_file
write "Copy index.html to index2.html: " & m_create_index2_files & RET to m_log_file
write "Backup start time: " & l_start_time & RET to m_log_file
write "=============================================================" & RET to m_log_file
end if

-- Get source folder length so that we can strip it out of each source folder's path
set l_source_length to (length of m_source_folder_string) + 1

-- Convert folder class to string (":...")
set l_destination_folder_unicode to m_destination_folder_string

-- Set queue items and start main repeat loop.
set l_record to {r_unicode_path:m_source_folder_string, r_alias:m_source_folder}
set l_pending_folders to {l_record}

-- While items remain in queue, process each one
repeat while ((length of l_pending_folders) > 0)

-- Remove the first item from l_pending_folders
set l_current_record to first item of l_pending_folders
if (length of l_pending_folders = 1) then
set l_pending_folders to {}
else
set l_pending_folders to rest of l_pending_folders
end if

-- extract contents of record
set l_current_folder to r_alias of l_current_record
set l_current_folder_string to r_unicode_path of l_current_record

-- Log current folder
if (m_log_folder_trace is true) then
log ("Checking folder for copy: " as Unicode text) & l_current_folder_string
if (class of m_log_file is not boolean) then
write ("Checking folder for copy: " as Unicode text) \
& l_current_folder_string & RET to m_log_file
end if
end if

-- Determine destination folder string
set l_unicode to l_current_folder_string as Unicode text
try
set l_unicode to (Unicode text l_source_length thru (length of l_unicode) of l_unicode)
on error l_error
-- error if this is the source folder base string
set l_unicode to ""
end try
set l_unicode to l_destination_folder_unicode & l_unicode

try
-- Determine destination folder.
set l_dest_folder to alias l_unicode

-- Cycle through items in the current folder and process each item
set l_items to list folder of l_current_folder
on error l_error
-- If there's an error, chances are dest folder doesn't exist.
-- Occurs when copying from Mac OS X to Mac OS 9 and file name
-- of source folder is illegal in Mac OS 9.
set l_dest_folder to ""
set l_items to {}

if (m_log_errors is true) then
log ("*****Error getting destination folder " as Unicode text) & l_unicode
log ("*****" as Unicode text) & l_error
if (class of m_log_file is not boolean) then
write ("*****Error getting destination folder " as Unicode text) \
& l_unicode & RET to m_log_file
write ("*****" as Unicode text) & l_error & RET to m_log_file
end if
end if
end try

-- l_temp_folders keeps track of folder list, so that we can
-- prepend it to l_pending_folders and do a depth-first search.
set l_temp_folders to {}

repeat with l_source_item_name in l_items

if (m_log_file_trace is true) then
log ("....Checking file for copy: " as Unicode text) \
& l_current_folder_string & l_source_item_name
if (class of m_log_file is not boolean) then
write ("....Checking file for copy: " as Unicode text) \
& l_current_folder_string & l_source_item_name & RET to m_log_file
end if
end if

set l_source_invalid to false

try
set l_source_item to (get item l_source_item_name of l_current_folder)
set l_copy_item to false
set l_dest_item to false
on error l_error
set l_source_invalid to true

if (m_log_errors is true) then
log ("*****Error processing source item " as Unicode text) \
& l_current_folder_string & l_source_item_name
log ("*****" as Unicode text) & l_error
if (class of m_log_file is not boolean) then
write ("*****Error processing source item " as Unicode text) \
& l_current_folder_string & l_source_item_name & RET to m_log_file
write ("*****" as Unicode text) & l_error & RET to m_log_file
end if
end if
end try

-- Check file name for excluded patterns: exact match
if (l_source_invalid is false) then
if (l_source_item_name is in m_filter_exact_files) then
if (m_log_decisions is true) then
log ("////Skipping filtered exact match: " as Unicode text) \
& l_current_folder_string & l_source_item_name
if (class of m_log_file is not boolean) then
write ("////Skipping filtered exact match: " as Unicode text) \
& l_current_folder_string & l_source_item_name & RET to m_log_file
end if
end if

set l_source_invalid to true
end if
end if

-- Check file name for excluded patterns: like match
if (l_source_invalid is false) then
repeat with l_pattern in m_filter_like_files
if l_pattern is in l_source_item_name then
if (m_log_decisions is true) then
log ("////Skipping filtered like match: " as Unicode text) \
& l_current_folder_string & l_source_item_name
if (class of m_log_file is not boolean) then
write ("////Skipping filtered like match: " as Unicode text) \
& l_current_folder_string & l_source_item_name & RET to m_log_file
end if
end if

set l_source_invalid to true
exit repeat
end if
end repeat
end if

-- Check file name for name too long
if (l_source_invalid is false and Â
m_filter_long_file_names is true and Â
length of l_source_item_name > 31) then

if (m_log_decisions is true) then
log ("////Skipping filtered name too long: " as Unicode text) \
& l_current_folder_string & l_source_item_name
if (class of m_log_file is not boolean) then
write ("////Skipping filtered name too long: " as Unicode text) \
& l_current_folder_string & l_source_item_name & RET to m_log_file
end if
end if

set l_source_invalid to true

end if

if (l_source_invalid is false) then

set l_source_kind to (get kind of l_source_item)
set l_source_date to (get modification date of l_source_item)

-- See if the item exists at the destination
try
set l_dest_item to (get item l_source_item_name of l_dest_folder)
set l_dest_kind to (get kind of l_dest_item)
set l_dest_date to (get modification date of l_dest_item)
on error l_error
set l_copy_item to true

if (m_log_decisions is true) then
log "////Destination item does not exist"
if (class of m_log_file is not boolean) then
write "////Destination item does not exist" & RET to m_log_file
end if
end if
end try

-- Check to see if source and destination differ.
if (l_copy_item is false) then
if (l_source_kind is not equal to l_dest_kind) then
-- First check class of items
set l_copy_item to true

if (m_log_decisions is true) then
log "////Source kind (" & l_source_kind & ") differs \
from destination kind (" & l_dest_kind & ")"
if (class of m_log_file is not boolean) then
write "////Source kind (" & l_source_kind & ") differs \
from destination kind (" & l_dest_kind & ")" & RET to m_log_file
end if
end if

else
if (m_ignore_exact_hours is true) then
set l_time_diff to (l_source_date - l_dest_date) mod 3600
else
set l_time_diff to l_source_date - l_dest_date
end if

if (m_copy_newer_files_only is true and Â
l_source_kind is not "Folder" and Â
l_time_diff > 0) then
-- Second, check source item is newer than destination. Only for non-folders
set l_copy_item to true

if (m_log_decisions is true) then
log "////Source date (" & l_source_date & ") is \
newer than destination date (" & l_dest_date & ")"
if (class of m_log_file is not boolean) then
write "////Source date (" & l_source_date & ") is \
newer than destination date (" & l_dest_date & ")" & RET to m_log_file
end if
end if

else if (m_copy_newer_files_only is false and Â
l_source_kind is not "Folder" and Â
l_time_diff is not equal to 0) then
-- Or, check date of source item is different than destination. Only for non-folders
set l_copy_item to true

if (m_log_decisions is true) then
log "////Source date (" & l_source_date & ") is \
different than destination date (" & l_dest_date & ")"
if (class of m_log_file is not boolean) then
write "////Source date (" & l_source_date & ") is \
different than destination date (" & l_dest_date & ")" & RET to m_log_file
end if
end if

end if
end if
end if

-- If we need to copy the item...
if (l_copy_item is true) then

-- Log event
if (m_log_actions is true) then
log ("++++Copying item " as Unicode text) & l_source_item
if (class of m_log_file is not boolean) then
write ("++++Copying item " as Unicode text) & l_source_item & RET to m_log_file
end if
end if

-- Copy source to destination
if (l_source_kind is not "Folder") then
-- If source is not a folder then copy it to destination
with timeout of 86400 seconds -- 1 day timeout
try
duplicate l_source_item to l_dest_folder with replacing
on error l_error
if (m_log_errors is true) then
log ("****" as Unicode text) & l_error
if (class of m_log_file is not boolean) then
write ("****" as Unicode text) & l_error & RET to m_log_file
end if
end if
end try
end timeout

-- Copy modification date of source to destination, only for non-folder items
if (l_dest_item is false) then
-- Destination did not exist, get it now
try
set l_dest_item to (get item l_source_item_name of l_dest_folder)
on error l_error
log ("****" as Unicode text) & l_error
if (class of m_log_file is not boolean) then
write ("****" as Unicode text) & l_error & RET to m_log_file
end if
end try
end if

if (l_dest_item is not false) then
try
set modification date of l_dest_item to l_source_date
on error l_error
log ("****" as Unicode text) & l_error
if (class of m_log_file is not boolean) then
write ("****" as Unicode text) & l_error & RET to m_log_file
end if
end try
end if
else
try
-- move or delete non-folder item
if (l_dest_item is not false and l_dest_kind is not "Folder") then
if (class of m_deleted_folder is alias) then
move l_dest_item to m_deleted_folder with replacing
else
delete l_dest_item
end if
end if
-- If source is a folder then create destination folder
set l_folder to make new folder at l_dest_folder
set name of l_folder to (l_source_item_name)
on error l_error
if (m_log_errors is true) then
log ("****" as Unicode text) & l_error
if (class of m_log_file is not boolean) then
write ("****" as Unicode text) & l_error & RET to m_log_file
end if
end if
end try
end if

-- !!! EXTRA !!!
-- If this item is index.html, duplicate it to index2.html and copy it over.
-- We only need to create index2.html if we're copying over index.html.
-- Extra copy covers case when index2.html did not initially exist.
if (m_create_index2_files is true and l_source_item_name \
as string is equal to "index.html") then
try
delete file "index2.html" of l_current_folder
on error l_error
end try

try
set l_dup to (duplicate l_source_item)
set name of l_dup to "index2.html"
on error l_error
end try

if (m_log_actions is true) then
log "++++Copying item index2.html"
if (class of m_log_file is not boolean) then
write "++++Copying item index2.html" & RET to m_log_file
end if
end if

with timeout of 86400 seconds -- 1 day timeout
try
duplicate file "index2.html" of l_current_folder to l_dest_folder with replacing
on error l_error
if (m_log_errors is true) then
log ("****" as Unicode text) & l_error
if (class of m_log_file is not boolean) then
write ("****" as Unicode text) & l_error & RET to m_log_file
end if
end if
end try
end timeout
end if

end if

-- If source item is a folder, add it to pending folders list
if (l_source_kind is "Folder") then
set l_item_string to l_current_folder_string & (get name of l_source_item) & ":"
set l_record to {r_unicode_path:l_item_string, r_alias:(l_source_item as alias)}
set l_temp_folders to l_temp_folders & {l_record}
end if
end if
end repeat

-- Prepend new folders to l_pending_folders
if ((count of l_temp_folders) > 0) then
set l_pending_folders to l_temp_folders & l_pending_folders
end if

-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-- Delete Destination Files Not In Source
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

if (class of l_dest_folder is not string) then

-- Log current folder
if (m_log_folder_trace is true) then
log ("Checking folder for delete: " as Unicode text) & l_dest_folder
if (class of m_log_file is not boolean) then
write ("Checking folder delete: " as Unicode text) & l_dest_folder & RET to m_log_file
end if
end if

-- Cycle through items in the current folder and process each item
set l_items to list folder of (l_dest_folder as alias)

repeat with l_destination_item_name in l_items

if (m_log_file_trace is true) then
log ("....Checking file for delete: " as Unicode text) \
& l_dest_folder & l_destination_item_name
if (class of m_log_file is not boolean) then
write ("....Checking file for delete: " as Unicode text) \
& l_dest_folder & l_destination_item_name & RET to m_log_file
end if
end if

set l_dest_invalid to false

try
set l_destination_item to (get item l_destination_item_name of l_dest_folder)
set l_delete_item to false
set l_source_item to ""
on error l_error
set l_dest_invalid to true
if (m_log_errors is true) then
log ("*****Error processing destination item " as Unicode text) \
& l_dest_folder & l_destination_item_name
log ("*****" as Unicode text) & l_error
if (class of m_log_file is not boolean) then
write ("*****Error processing destination item " as Unicode text) \
& l_dest_folder & l_destination_item_name & RET to m_log_file
write ("*****" as Unicode text) & l_error & RET to m_log_file
end if
end if
end try

-- Check file name for excluded patterns: exact match
if (l_dest_invalid is false) then
if (l_destination_item_name is in m_filter_exact_files) then
if (m_log_decisions is true) then
log ("////Skipping filtered exact match: " as Unicode text) \
& l_dest_folder & l_destination_item_name
if (class of m_log_file is not boolean) then
write ("////Skipping filtered exact match: " as Unicode text) \
& l_dest_folder & l_destination_item_name & RET to m_log_file
end if
end if

set l_dest_invalid to true
end if
end if

-- Check file name for excluded patterns: like match
if (l_dest_invalid is false) then
repeat with l_pattern in m_filter_like_files
if l_pattern is in l_destination_item_name then
if (m_log_decisions is true) then
log ("////Skipping filtered like match: " as Unicode text) \
& l_dest_folder & l_destination_item_name
if (class of m_log_file is not boolean) then
write ("////Skipping filtered like match: " as Unicode text) \
& l_dest_folder & l_destination_item_name & RET to m_log_file
end if
end if

set l_dest_invalid to true
exit repeat
end if
end repeat
end if

if (l_dest_invalid is false) then
-- See if the item exists at the destination
try
set l_source_item to (get item l_destination_item_name of l_current_folder)
on error l_error
set l_delete_item to true
end try

-- If we need to delete the item...
if (l_delete_item is true) then

-- Log event
if (m_log_actions is true) then
log ("----Deleting item " as Unicode text) & l_destination_item as string
if (class of m_log_file is not boolean) then
write ("----Deleting item " as Unicode text) & l_destination_item & RET to m_log_file
end if
end if

-- Delete destination
try
if (class of m_deleted_folder is alias) then
move l_destination_item to m_deleted_folder with replacing
else
delete l_destination_item
end if
on error l_error
if (m_log_errors is true) then
log ("****" as Unicode text) & l_error
if (class of m_log_file is not boolean) then
write ("****" as Unicode text) & l_error & RET to m_log_file
end if
end if
end try

end if

end if
end repeat
end if
end repeat

-- Log end time
log "============================================================="
log ("Backup source: " as Unicode text) & m_source_folder_string
log ("Backup destination: " as Unicode text) & m_destination_folder_string
log ("Deleted folder: " as Unicode text) & m_deleted_folder_string
log ("Log file: " as Unicode text) & m_log_file_string
log "Log options: " & l_choices_string
log "Copy only if source is newer: " & m_copy_newer_files_only
log "Ignore exact hour differences: " & m_ignore_exact_hours
log ("Filter exact files: " as Unicode text) & m_filter_exact_files
log ("Filter like files: " as Unicode text) & m_filter_like_files
log "Ignore files with long names: " & m_filter_long_file_names
log "Copy index.html to index2.html: " & m_create_index2_files
log "Backup start time: " & l_start_time as string
log "Backup end time: " & (current date)
log "============================================================="
if (class of m_log_file is not boolean) then
write "=============================================================" & RET to m_log_file
write ("Backup source: " \
as Unicode text) & m_source_folder_string & RET to m_log_file
write ("Backup destination: " \
as Unicode text) & m_destination_folder_string & RET to m_log_file
write ("Deleted folder: " \
as Unicode text) & m_deleted_folder_string & RET to m_log_file
write ("Log file: " \
as Unicode text) & m_log_file_string & RET to m_log_file
write "Log options: " & l_choices_string & RET to m_log_file
write "Copy only if source is newer: " & m_copy_newer_files_only & RET to m_log_file
write "Ignore exact hour differences: " & m_ignore_exact_hours & RET to m_log_file
write ("Filter exact files: " \
as Unicode text) & m_filter_exact_files & RET to m_log_file
write ("Filter like files: " \
as Unicode text) & m_filter_like_files & RET to m_log_file
write "Ignore files with long names: " & m_filter_long_file_names & RET to m_log_file
write "Copy index.html to index2.html: " & m_create_index2_files & RET to m_log_file
write "Backup start time: " & l_start_time & RET to m_log_file
write "Backup end time: " & (current date) & RET to m_log_file
write "=============================================================" \
& RET to m_log_file
close access m_log_file
end if
end if

end tell

Copyright (c) 2001 Kevin C. Wong
Page Created: August 21, 2004
Page Last Updated: August 21, 2004