Now we're ready for the main loop. First is the repeat
while condition. We
keep going through the loop until l_offset = 0. How does this happen?
Let's
take a look at the last record to be deleted. l_filelist will look
like:
"ATA_02:Kevin:Temp copy:chill2.mov ATA_02:Kevin:Temp copy:cuba_gooding_jr_6.jpg "
Note that chill2.mov has already been deleted and l_offset points to
the
"\r\t" between chill2.mov and cuba_gooding_jr_6.jpg. The script strips
out
the first part of l_offset, leaving:
"ATA_02:Kevin:Temp copy:cuba_gooding_jr_6.jpg "
Then when it looks for the next "\r\t", there is none so l_offset is
set to 0.
The file cuba_gooding_jr_6.jpg is deleted and at the next iteration the
loop
exits.
repeat while (l_offset > 0)
-- extract out first element in remaining list set l_filelist to extract string l_filelist from (l_offset + 2)
Note here how we strip out the last file deleted, plus the "\r\t" after
it.
l_offset + 2 points to the next character after "\r\t" and so
l_filelist starts
immediately with the next file to be deleted.
-- find offset of next delimiter set l_offset to offset of "\r\t" in l_filelist -- check to see if there is another delimiter if (l_offset = 0) then -- no other elements set l_file to extract string l_filelist  from 1 to ((length of l_filelist) - 1) else -- at least one other element set l_file to extract string l_filelist  from 1 to (l_offset - 1) end if
This part is a bit important. If l_offset equals 0, then this is the
last
file to delete, and the last one in l_filelist. So we can just pass the
whole
string (minus the ending return character) to the delete command. If
l_offset
is greater than 0, then there will be more files to delete. So we can
pass
the substring starting from the beginning and ending just before
l_offset to
the delete command. In either case, l_file ends up with the file
specification
that must be deleted.
More in the next journal...
|