Scripting Additions Guide

CHAPTER 2
Scripting Addition Commands
Using Read/Write Commands 75
try
set x to open for access pathToUse with write permission
DeleteRecord(10, 1, tab, return, x)
close access x
on error errString number errNum
display dialog errString
close access x
end try
on DeleteRecord(numberOfFields, whichRecord, ¬
fieldDelimiter, recordDelimiter, fileRefNum)
try
--initialize variables
set startSize to get eof fileRefNum --current size
set idx to 1 --counter
set preRecordSize to 1 --offset of record to delete
set accumulatedSize to 0 --total size of records read
if recordDelimiter is "" then
set readxTimes to numberOfFields
else
set readxTimes to numberOfFields - 1
end if
repeat with idx from 1 to whichRecord
repeat (readxTimes) times
set q to read fileRefNum until fieldDelimiter
set accumulatedSize to accumulatedSize + (length of q)
end repeat
if readxTimes is not numberOfFields then
set q to read fileRefNum until recordDelimiter
set accumulatedSize to accumulatedSize + (length of q)
end if