FileIO Parent: Examples

This document provides some rudimentary code examples to demonstrate usage of the FileIO Parent Script.

Example code currently available:

1. Convert Text File Between Platforms

-- This handler converts a text file to a specific platform format.
-- (ie: this puts the correct line terminator at the end of each line)

-- sSrcFile: path/filename of source text file
-- sDestFile: path/filename of new file to create
-- sFormat: #win, #mac, #unix

-- e.g.: _Convert("d:\file_unix.txt", "d:\file_pc.txt", #win)

on _Convert sSrcFile, sDestFile, sDestFormat

oFileRead = new(script "FileIO Parent", sSrcFile, #read)

oFileWrite = new(script "FileIO Parent", sDestFile, #write)
oFileWrite._DefineTerminator(sDestFormat)


repeat while (NOT oFileRead._IsPastEOF()) -- if we are not at the end of the file
sLine = oFileRead._ReadLine(#stripcr) -- read a line and strip CR/LF characters
oFileWrite._WriteLine(sLine, #addcr) -- write line to new file, with new line terminator
end repeat


oFileRead._Kill() -- close the files
oFileWrite._Kill()

oFileRead = void -- housekeeping cleanup
oFileWrite = void

end