kcw | journal | 2000 << Previous Page | Next Page >>
	-- Find the start of the header portion.
-- Note that the backup command has two sections,
-- one for files to replace (ElŽments ˆ mettre ˆ jour)
-- and one for files to create (ElŽments ˆ crŽer).
-- (ElŽments ˆ mettre ˆ jour) comes first, so after
-- (ElŽments ˆ crŽer), the remaining elements of the
-- string are all filenames.

set l_offset to Â
offset of "ElŽments ˆ crŽer :" in l_filelist

Here we use the offset command (in the Standard Scripting Additions) to find the start of the files to create section. Note that if there are no files to create, this section will be totally missing from l_filelist, so offset will return 0. Strings in Applescript run from subscript 1 to n.

	-- if the offset == 0 then no files to create.
if (l_offset > 0) then

First we check to see if the files to create section was found, if not then the script skips to the end and exits. There is no AppleScript exit command, which makes it a bit harder to prematurely exit a script. Procedures can just Return, making them easier to exit from.

Here's what I want to do in the main loop. At each iteration, l_filelist contains the list of files to delete, plus the file that was just deleted. l_offset contains the location of the next "\r\t", which signifies the end of the current record and the start of the next record. So we strip the last record out, then get the next record and delete that file, then reset l_offset to the next record delimiter.

Before the start of the loop, I have to set it up for the first iteration.

		-- extract files to 'create files' section
-- extract string command from Satimage Additions
set l_filelist to extract string l_filelist from l_offset

-- Each element is delimited by "\r " or something similar
set l_offset to offset of "\r\t" in l_filelist

Extract string is a command in Satimage Additions, it returns a substring of the given string, from position x to position y. If position y is not given then it returns a string from position x to the end of the string. If x is greater than the length of the string then it returns "" (an empty string).

So here we are extracting any files to change section (which comes before the files to create section) in the backup output. Then we set l_offset to the first record, which means that the "last" record was the "ElŽments ˆ crŽer :" section header.

More in the next entry...


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