To follow up the post about writing a text file with Automation I would also like to post about reading a text file with that same Automation.  Now we add the automation automation ‘Windows Script Host Object Model’.File.  First you need to create a file system object ‘Windows Script Host Object Model’.FileSystemObject. Then open the file in the File automation to get the size of the file. Finally open the textstream and start reading. This will give you correct progress dialog and the correct character set when reading.
[code htmlscript=”false”]IF FileName = ” THEN
ERROR(Text001);

CLEAR(SystemFilesSystem);
CREATE(SystemFilesSystem,TRUE,TRUE);

IF NOT SystemFilesSystem.FileExists(FileName) THEN
ERROR(Text002);

SystemFile := SystemFilesSystem.GetFile(FileName);
SystemTextStream := SystemFile.OpenAsTextStream;
FileSize := SystemFile.Size;
FilePos := 0;

Window.OPEN(Text003 + ‘\\@1@@@@@@@@@@@@@@@@@@@@’);
WindowLastUpdated := CURRENTDATETIME;
WHILE NOT SystemTextStream.AtEndOfStream DO BEGIN
Line := SystemTextStream.ReadLine;
FilePos := FilePos + STRLEN(Line) + 2;

‘Handle Line

IF (CURRENTDATETIME – WindowLastUpdated) > 100 THEN BEGIN
Window.UPDATE(1,ROUND(FilePos / FileSize * 10000,1));
WindowLastUpdated := CURRENTDATETIME;
END;
END;
Window.Close;
SystemTextStream.Close;
CLEAR(SystemFilesSystem);[/code]
 

Leave a Reply

%d bloggers like this: